我试图使用Email::Send::Gmail发送电子邮件,但由于某些原因,我收到了一个错误,它不允许我连接。
代码是标准示例:
#!/usr/bin/perl
use strict;
use warnings;
use Email::Send;
use Email::Send::Gmail;
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
From => 'myaddress@gmail.com',
To => 'myaddress@gmail.com',
Subject => 'Server down',
],
body => 'The server is down. Start panicing.',
);
my $sender = Email::Send->new(
{ mailer => 'Gmail',
mailer_args => [
username => 'myaddress@gmail.com',
password => 'XXXX',
]
}
);
eval { $sender->send($email) };
die "Error sending email: $@" if $@;准确的错误是:
Email::Send::Gmail: error connecting to server smtp.gmail.com
at C:/Perl/site/lib/Email/Send.pm line 256.我已经查看了我的gmail帐户,似乎没有任何东西可以“允许访问”。我在Windows7上运行,从命令行运行。
有什么想法吗?
谢谢,A
发布于 2014-05-22 03:28:49
该升级您的依赖项了。
Email::Gmail::Send依赖于Net::SMTP::SSL,而依赖于IO::Socket::SSL。解决这类问题的第一步是升级模块依赖关系,以防已经解决了新问题。
不幸的是,4天前,当您第一次介绍这个问题时,我无法通过IO::Socket::SSL 1.986 on Strawberry Perl 5.18.2的测试套件。
t/public_suffix_lib_uri.t ......... ok
failed to connect: An operation was attempted on something that is not a socket. at t/public_suffix_ssl.t line 87.
# Looks like you planned 24 tests but ran 2.
# Looks like your test exited with 10038 just after 2.幸运的是,从那时起,作者将模块更新为IO::Socket::SSL 1.988,我能够在Windows7和Linux上完全安装和使用它。目前,它会引发重新定义的警告(cpan ticket 95881),但在升级此依赖项后,我能够在Windows上发送Gmail消息。
注意:您将希望为此代码创建一个application specific password,否则Gmail可能会阻止登录,并向您发送一个“可疑登录阻止”电子邮件。
发布于 2015-12-28 12:03:07
只需升级您的活动Perl版本即可。
然后安装以下模块: ppm
然后尝试使用下面的示例代码。
#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use Email::Send;
use Email::Send::Gmail;
use Email::Simple::Creator;
my $email = Email::Simple->create (
header => [
From => '@gmail.com',
To => '@gmail.com',
Subject => 'Make it simple',
],
body => 'buddy I got it ...',
);
my $sender = Email::Send->new
({
mailer => 'Gmail',
mailer_args =>
[
username => '',
password => '',
]
});
$sender->send ($email);https://stackoverflow.com/questions/23704058
复制相似问题