正在安装 Net::SMTP::SSL
Installing Net::SMTP::SSL
您好,当我尝试在我的 Mac 上使用 Net::SMTP::SSL 时遇到了 运行 问题 (运行ning OS X 10.10)。我有一个 perl 脚本 运行 使用 Net::SMTP::SSL 没问题,它看起来像这样:
use Net::SMTP::SSL;
use strict;
use Carp;
use Pod::Usage;
sub send_mail {
my $to = 'phone@server.com';
my $subject = $_[1];
my $body = $_[2];
my $from = 'mail@server.com';
my $password = 'password';
my $smtp;
if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com',
Port => 465,
Debug => 1)) {
die "Could not connect to server\n";
}
$smtp->auth($from, $password)
|| die "Authentication failed!\n";
$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
$smtp->to($recp . "\n");
}
$smtp->data();
$smtp->datasend("From: " . $from . "\n");
$smtp->datasend("To: " . $to . "\n");
$smtp->datasend("Subject: " . $subject . "\n");
$smtp->datasend("\n");
$smtp->datasend($body . "\n");
$smtp->dataend();
$smtp->quit;
}
# Send away!
&send_mail('mail@server.com', 'Server just blew up', 'Some more detail');
我还有另一个脚本(在单独的文件夹中),开头为:
#!/usr/bin/env perl -Ilib
use Net::SMTP::SSL;
我的问题是第二个脚本不起作用。我收到一个命令行错误报告它在@INC
中找不到 Net/SMTP/SSL.pm
我已将问题缩小到 shebang 部分 #!/usr/bin/env perl -Ilib 但我不知道如何解决它。有什么建议吗?
最近,当我试图调查一个失败的脚本时,我才意识到 Net::SMTP::SSL 有多老。由于
加载模块失败
no strict 'refs';
foreach ( keys %Net::SMTP:: ) {
next unless defined *{$Net::SMTP::{$_}}{CODE};
*{$_} = \&{"Net::SMTP::$_"};
}
在Net/SMTP/SSL.pm
中:
[~/tmp/Net-SMTP-SSL-1.01]> prove -vb t/test.t
t/test.t ..
1..1
not ok 1 - use Net::SMTP::SSL;
# Failed test 'use Net::SMTP::SSL;'
# at t/test.t line 2.
# Tried to use 'Net::SMTP::SSL'.
# Error: Not a GLOB reference at /Users/.../tmp/Net-SMTP-SSL-1.01/blib/lib/Net/SMTP/SSL.pm line 16.
# Compilation failed in require at t/test.t line 2.
# BEGIN failed--compilation aborted at t/test.t line 2.
# Looks like you failed 1 test of 1.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests
...
Result: FAIL
事实证明,在随后的十年中,Net::SMTP 现在包含了所需的功能。所以,就用那个吧。
$ perl -MNet::SMTP -E 'say Net::SMTP->can_ssl'
IO::Socket::SSL
您好,当我尝试在我的 Mac 上使用 Net::SMTP::SSL 时遇到了 运行 问题 (运行ning OS X 10.10)。我有一个 perl 脚本 运行 使用 Net::SMTP::SSL 没问题,它看起来像这样:
use Net::SMTP::SSL;
use strict;
use Carp;
use Pod::Usage;
sub send_mail {
my $to = 'phone@server.com';
my $subject = $_[1];
my $body = $_[2];
my $from = 'mail@server.com';
my $password = 'password';
my $smtp;
if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com',
Port => 465,
Debug => 1)) {
die "Could not connect to server\n";
}
$smtp->auth($from, $password)
|| die "Authentication failed!\n";
$smtp->mail($from . "\n");
my @recepients = split(/,/, $to);
foreach my $recp (@recepients) {
$smtp->to($recp . "\n");
}
$smtp->data();
$smtp->datasend("From: " . $from . "\n");
$smtp->datasend("To: " . $to . "\n");
$smtp->datasend("Subject: " . $subject . "\n");
$smtp->datasend("\n");
$smtp->datasend($body . "\n");
$smtp->dataend();
$smtp->quit;
}
# Send away!
&send_mail('mail@server.com', 'Server just blew up', 'Some more detail');
我还有另一个脚本(在单独的文件夹中),开头为:
#!/usr/bin/env perl -Ilib
use Net::SMTP::SSL;
我的问题是第二个脚本不起作用。我收到一个命令行错误报告它在@INC
中找不到 Net/SMTP/SSL.pm我已将问题缩小到 shebang 部分 #!/usr/bin/env perl -Ilib 但我不知道如何解决它。有什么建议吗?
最近,当我试图调查一个失败的脚本时,我才意识到 Net::SMTP::SSL 有多老。由于
加载模块失败no strict 'refs';
foreach ( keys %Net::SMTP:: ) {
next unless defined *{$Net::SMTP::{$_}}{CODE};
*{$_} = \&{"Net::SMTP::$_"};
}
在Net/SMTP/SSL.pm
中:
[~/tmp/Net-SMTP-SSL-1.01]> prove -vb t/test.t t/test.t .. 1..1 not ok 1 - use Net::SMTP::SSL; # Failed test 'use Net::SMTP::SSL;' # at t/test.t line 2. # Tried to use 'Net::SMTP::SSL'. # Error: Not a GLOB reference at /Users/.../tmp/Net-SMTP-SSL-1.01/blib/lib/Net/SMTP/SSL.pm line 16. # Compilation failed in require at t/test.t line 2. # BEGIN failed--compilation aborted at t/test.t line 2. # Looks like you failed 1 test of 1. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/1 subtests ... Result: FAIL
事实证明,在随后的十年中,Net::SMTP 现在包含了所需的功能。所以,就用那个吧。
$ perl -MNet::SMTP -E 'say Net::SMTP->can_ssl' IO::Socket::SSL