2

我有一个简单的测试脚本,用于使用 cpan 模块 Mail::Sendmail 向自己发送电子邮件。我正在使用 Strawberry Perl 并通过命令行在 Windows 机器上操作,一切似乎都很好。我收到一条错误消息connect to localhost failed (No connection could be made because the target machine refused it.)

我的脚本是:

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;

有什么理由会发生这种情况吗?

4

1 回答 1

1

默认情况下,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';"
于 2012-08-06T18:59:14.707 回答