我有一个简单的测试脚本,用于使用 cpan 模块 Mail::Sendmail 向自己发送电子邮件。我正在使用 Strawberry Perl 并通过命令行在 Windows 机器上操作,一切似乎都很好。我收到一条错误消息,提示 connect to localhost failed (No connection could be made because the target machine refused.)
我的脚本是:
use Mail::Sendmail qw(sendmail %mailcfg);
$mailcfg{from} = 'dhagan@idatech.com';
print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION\n";
print "Default server: $Mail::Sendmail::mailcfg{smtp}->[0]\n";
print "Default sender: $Mail::Sendmail::mailcfg{from}\n";
%mail = ( To => 'dhagan@email.com',
From => 'dhagan@email.com',
Message => 'Test!'
);
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log;
有什么原因会发生这种情况吗?
最佳答案
默认情况下,Mail::Sendmail 被配置为将邮件发送到本地主机,但您没有在那里运行 SMTP 服务器。
您必须配置合适的服务器 - 请参阅帮助。
Default SMTP server(s)
This is probably all you want to configure. It is usually done
through $mailcfg{smtp}, which you can edit at the top of the
Sendmail.pm file. This is a reference to a list of SMTP servers.
You can also set it from your script:
"unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.mail.server';"
Alternatively, you can specify the server in the %mail hash you
send from your script, which will do the same thing:
"$mail{smtp} = 'my.mail.server';"
关于windows - 使用 Mail::Sendmail 使用 Windows 机器从 perl 脚本发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832929/