windows - Perl:SMTP 无法连接到邮件服务器

标签 windows perl email smtp

我编写了一个简单的 Perl 脚本来使用 MIME::Lite 和 Net::SMTP 模块发送邮件。但它导致错误,“SMTP 无法连接到邮件服务器:无法立即完成非阻塞套接字操作”

我尝试过的Perl脚本,

use strict;
use warnings;
use MIME::Lite;
use Net::SMTP;

my $from = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1071777e756377626563647566757e50777d71797c3e737f7d" rel="noreferrer noopener nofollow">[email protected]</a>';
my $to = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f495939a918793868187809182919ab49399959d98da979b99" rel="noreferrer noopener nofollow">[email protected]</a>';
my $host = 'smtp.gmail.com';

my $subject = 'A test  message by script ';
my $body = "Please ignore this message as this is test from Perl scripts ";

my $msg = MIME::Lite->new (
  From => $from,
  To => $to,
  Subject => $subject,
  Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

$msg->attach (
  Type => 'TEXT',
  Data => $body
) or die "Error adding the text message part: $!\n";

MIME::Lite->send('smtp', $host, Timeout=>60);
$msg->send;

我得到的实际错误,

G:\>perl SampleEmail.pl
SMTP Failed to connect to mail server: A non-blocking socket operation could not
 be completed immediately.
 at SampleEmail.pl line 26.

请帮助我具体需要检查什么才能正确发送邮件。

提前致谢

最佳答案

MIME::Lite/Net::SMTP v3.* - 通过 smtp.gmail.com 发送

问题1:您可以远程登录 smtp.gmail.com 上的 smtp (25) 端口吗?您收到 SMTP 问候消息吗?

telnet smtp.gmail.com 25

A1:否 => 您到 smtp 端口的传出连接很可能被阻止,以避免传出垃圾邮件。

问题2:您可以远程登录 smtp.gmail.com 上的 msa (587) 端口吗?您收到 SMTP 问候消息吗?

telnet smtp.gmail.com 587

A1:是 => 通过 msa (587) 或 smtps (465) 发送。 MIME::Lite 可以使用 Net::SMTP 版本 3.* 连接到 smtps (465) 端口。
[警告:请参阅MIME::Lite 3.030 - NET::SMTP with smtps (port 465) ]

# use smtps (465) port - it requires Net::SMTP version 3.*
# use debugging (Debug=>1) for initial tests
MIME::Lite->send('smtp', $host, SSL => 1, Timeout => 60,
  AuthUser => $user, AuthPass => $pass, 
  Debug => 1);

关于windows - Perl:SMTP 无法连接到邮件服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316699/

相关文章:

regex - Perl:我可以在变量中存储反向引用(不是它们的值)吗?

c - 获取系统显示颜色设置

linux - 我可以在 Windows 中用什么程序编写 .sh 文件

windows - Windows 是否提供我可以用来实现免费试用的唯一标识符?

perl - 将 form-urlencoded 解码为哈希

perl - 使用 MooseX::Declare 关闭内联构造函数

php - 如果您的防火墙设置阻止了 993 端口,您如何取消阻止它?

python - 通过 SMTP Python 发送电子邮件时遇到问题

delphi - 使用 TLS 从 DELPHI(Indy) 使用 Gmails 传出 SMTP

java - 在 Windows 中设置默认堆大小