为什么 Perl 的 MIME::Lite 失败并显示“” SMTP data() 命令失败:2.1.5 ... 收件人正常”?

发布于 2024-09-19 11:40:41 字数 6299 浏览 9 评论 0原文

这可能是一个对 SO 和 SF 都有效的交叉问题。 我正在使用如下 Perl 脚本来发送电子邮件:

my $SMTP_SERVER = 'xx.xx.xx.xx'; 
my $DEFAULT_SENDER = '[email protected]';      
my $DEFAULT_RECIPIENT = '[email protected]';

### Create the multipart "container":
$msg = MIME::Lite->new(
    From    =>$DEFAULT_SENDER,
    To      =>$input{to},
    Cc      =>$DEFAULT_SENDER,
    Subject =>$input{mailsubject},
    Type    =>'multipart/mixed'
);


my $msgbody="<body bgcolor=\"#C0C0C0\">\n";
   $msgbody.="<img src="cid:xyz.gif"><br>O hai thar.."
   $msgbody.="</body>";


### Add the text message part:
### (Note that "attach" has same arguments as "new"):
$msg->attach(
    Type     =>'text/html',
    Data     =>$msgbody
);

### Add the logo image part:    
$msg->attach(
    Type => 'image/gif',
    Id   => 'xyz.gif',
    Path => '/var/www/images/xyz.gif',
);


### Add the file part:
$msg->attach(
    Type        =>'application/zip',
    Path        =>$input{fullpath},
    Filename    =>$input{file},
    Disposition => 'attachment'
);

open ERROR,  '>>', "/debug/error.txt"  or die $!;
STDERR->fdopen( \*ERROR,  'w' );

eval{

# send the email
MIME::Lite->send('smtp', $SMTP_SERVER, Timeout=>30, Debug=>1, Notify => ['FAILURE','DELAY'], SkipBad => 1 );
$msg->send();

1;
}
or do{&error($@)};

close ERROR;

现在这个脚本对于 98% 的已发送电子邮件来说效果很好.. 然而.. 2% 的大客户端是我现在正在试图弄清楚的。每当我发送到此客户端时,我都会收到消息: SMTP data() command failed: 2.1.5 ... Recipient ok

有人以前见过这个错误或者知道我的问题出在哪里吗?我尝试替换 X-Mailer: 标题,认为该标题已被垃圾邮件过滤。我尝试向我们域中的其他人发送相同的消息,但该消息不适用于此客户端 URL。

下面的示例标题:

MIME-Version: 1.0 
Content-Transfer-Encoding: binary 
Content-Type: multipart/mixed; 
boundary="_----------=_12845827796770" 
X-Mailer: MIME::Lite 3.027 (F2.76; T1.29; A2.03; B3.07_01; Q3.07) 
Date: Wed, 15 Sep 2010 13:37:59 -0700 
From: [email protected] 
To: [email protected], [email protected], [email protected] 
Cc: [email protected] 
Subject: TEST

有任何线索吗?

此外,直接使用 Outlook 发送具有相同附件的电子邮件与此客户端和相同的 smtp 服务器完美配合。只有当通过这个自动化过程发送时,错误才会出现。

更新: 调试日志(这让我认为这是一个很大的延迟问题,响应异步返回并在 MIME::Lite 过程中恢复正常的操作流程)

MIME::Lite::SMTP>>> MIME::Lite::SMTP
MIME::Lite::SMTP>>>   Net::SMTP(2.31)
MIME::Lite::SMTP>>>     Net::Cmd(2.29)
MIME::Lite::SMTP>>>       Exporter(5.62)
MIME::Lite::SMTP>>>     IO::Socket::INET(1.31)
MIME::Lite::SMTP>>>       IO::Socket(1.30_01)
MIME::Lite::SMTP>>>         IO::Handle(1.27)
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 220 smpt.xxx.com ESMTP Sendmail 8.12.9/8.13.1; Wed, 15 Sep 2010 16:50:44 -0700 (PDT)
MIME::Lite::SMTP=GLOB(0x84ac258)>>> EHLO localhost.localdomain
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-smpt.xxx.com Hello [xx.xx.xx.xx], pleased to meet you
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-ENHANCEDSTATUSCODES
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-PIPELINING
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-8BITMIME
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-SIZE
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-DSN
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-ETRN
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-DELIVERBY
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 HELP
MIME::Lite::SMTP=GLOB(0x84ac258)>>> MAIL FROM:<[email protected]>
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.0 <[email protected]>... Sender ok
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:41:22 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:41:52 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:42:22 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.5 <[email protected]>... Recipient ok
MIME::Lite::SMTP=GLOB(0x84ac258)>>> DATA
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.5 <[email protected]>... Recipient ok

This is probably a crossover question that is valid for both SO and SF.
I am using a Perl script as follows to send e-mail:

my $SMTP_SERVER = 'xx.xx.xx.xx'; 
my $DEFAULT_SENDER = '[email protected]';      
my $DEFAULT_RECIPIENT = '[email protected]';

### Create the multipart "container":
$msg = MIME::Lite->new(
    From    =>$DEFAULT_SENDER,
    To      =>$input{to},
    Cc      =>$DEFAULT_SENDER,
    Subject =>$input{mailsubject},
    Type    =>'multipart/mixed'
);


my $msgbody="<body bgcolor=\"#C0C0C0\">\n";
   $msgbody.="<img src="cid:xyz.gif"><br>O hai thar.."
   $msgbody.="</body>";


### Add the text message part:
### (Note that "attach" has same arguments as "new"):
$msg->attach(
    Type     =>'text/html',
    Data     =>$msgbody
);

### Add the logo image part:    
$msg->attach(
    Type => 'image/gif',
    Id   => 'xyz.gif',
    Path => '/var/www/images/xyz.gif',
);


### Add the file part:
$msg->attach(
    Type        =>'application/zip',
    Path        =>$input{fullpath},
    Filename    =>$input{file},
    Disposition => 'attachment'
);

open ERROR,  '>>', "/debug/error.txt"  or die $!;
STDERR->fdopen( \*ERROR,  'w' );

eval{

# send the email
MIME::Lite->send('smtp', $SMTP_SERVER, Timeout=>30, Debug=>1, Notify => ['FAILURE','DELAY'], SkipBad => 1 );
$msg->send();

1;
}
or do{&error($@)};

close ERROR;

Now this script works lovely for 98% of the e-mails sent.. however.. the big 2% client is the one I am trying to figure out now. Whenever I send to this client in particular I get the message: SMTP data() command failed: 2.1.5 ... Recipient ok .

Has anyone seen this error before or have any idea as to where my problem is? I tried replacing the X-Mailer: header thinking that was being spam filtered. I tried sending the same message to others on our domain and that works just not to this client URL.

example header below:

MIME-Version: 1.0 
Content-Transfer-Encoding: binary 
Content-Type: multipart/mixed; 
boundary="_----------=_12845827796770" 
X-Mailer: MIME::Lite 3.027 (F2.76; T1.29; A2.03; B3.07_01; Q3.07) 
Date: Wed, 15 Sep 2010 13:37:59 -0700 
From: [email protected] 
To: [email protected], [email protected], [email protected] 
Cc: [email protected] 
Subject: TEST

Any clues?

Also, sending an e-mail directly using Outlook with same attachments works perfectly with this client and same smtp server. It is only when being sent via this automated process that the error rears it's ugly head.

Update:
Debug Log (which has me thinking it is a big latency issue where the responses are coming back asynch and hosing up the normal flow of operations in the process of MIME::Lite)

MIME::Lite::SMTP>>> MIME::Lite::SMTP
MIME::Lite::SMTP>>>   Net::SMTP(2.31)
MIME::Lite::SMTP>>>     Net::Cmd(2.29)
MIME::Lite::SMTP>>>       Exporter(5.62)
MIME::Lite::SMTP>>>     IO::Socket::INET(1.31)
MIME::Lite::SMTP>>>       IO::Socket(1.30_01)
MIME::Lite::SMTP>>>         IO::Handle(1.27)
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 220 smpt.xxx.com ESMTP Sendmail 8.12.9/8.13.1; Wed, 15 Sep 2010 16:50:44 -0700 (PDT)
MIME::Lite::SMTP=GLOB(0x84ac258)>>> EHLO localhost.localdomain
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-smpt.xxx.com Hello [xx.xx.xx.xx], pleased to meet you
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-ENHANCEDSTATUSCODES
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-PIPELINING
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-8BITMIME
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-SIZE
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-DSN
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-ETRN
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250-DELIVERBY
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 HELP
MIME::Lite::SMTP=GLOB(0x84ac258)>>> MAIL FROM:<[email protected]>
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.0 <[email protected]>... Sender ok
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:41:22 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:41:52 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
[Wed Sep 15 16:42:22 2010] myemailscript.cgi: MIME::Lite::SMTP=GLOB(0x84ac258): Timeout at /usr/local/share/perl/5.10.0/MIME/Lite.pm line 2889
MIME::Lite::SMTP=GLOB(0x84ac258)>>> RCPT TO:<[email protected]>
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.5 <[email protected]>... Recipient ok
MIME::Lite::SMTP=GLOB(0x84ac258)>>> DATA
MIME::Lite::SMTP=GLOB(0x84ac258)<<< 250 2.1.5 <[email protected]>... Recipient ok

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔 2024-09-26 11:40:41

Net::SMTP 客户端似乎超时,但对 RCTP TO 的响应最终会在不再预期时到达。尝试将超时设置为 300 秒而不是 30 秒?

The Net::SMTP client appears to be timing out, but the responses to the RCTP TO's are arriving eventually when they are no longer expected. Try setting the timeout to 300 seconds instead of 30?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文