windows - 使用 Mail::Sendmail 使用 Windows 机器从 perl 脚本发送电子邮件时出错

标签 windows perl email sendmail

我有一个简单的测试脚本,用于使用 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/

相关文章:

c++ - 可以在 Windows 中使用 clang-cl 标志 -fprofile-instr-generate -fcoverage-mapping

windows - 使用不同的进程名称执行批处理文件

string - Perl:在 excel/csv 文件中查找重复项并用它们编写输出文件

ios - 验证 iOS 中电子邮件域中的字符数?

java - 在 javax.mail.MimeMessage 中设置发件人名称?

email - 通过 message_id 从 imap 检索单个电子邮件

python - 从 Python 修改 Windows 环境变量的接口(interface)

c++ - 在 UDP 套接字上多次调用 connect() 以发送到不同的目标地址 - 有效吗?

perl - 是否可以为依赖于用户输入的模块编写自测?

perl - perl require 语句有必要吗?