【发布时间】:2018-01-01 09:21:44
【问题描述】:
我尝试使用 Mime::Lite perl 模块并通过 smtp 身份验证发送电子邮件。但不幸的是,这不起作用。它显示了
错误:需要 MAIL 命令,错误:命令未实现
这是更新后的代码 sn-p 和调试输出。
#!/usr/bin/perl
use warnings;
use strict;
use MIME::Lite;
use Net::SMTP;
use MIME::Base64;
my $smtp = Net::SMTP->new(<mail host>,Port=>587,Debug=>1)or die;
$smtp->starttls();
$smtp->auth($username,$password) or die $!;
my $msg = MIME::Lite -> new (
From => 'from@mail.com',
TO => 'to@mail.com',
Subject => 'Testing Text Message',
Data => 'How\'s it going.' );
$smtp->mail(<from mail>);
$smtp->to(<to mail>);
$smtp -> data();
$smtp -> datasend( $msg->as_string() );
$smtp -> dataend();
print $smtp ->message();
$smtp -> quit;
调试输出:
Net::SMTP>>> Net::SMTP(3.10)
Net::SMTP>>> Net::Cmd(3.10)
Net::SMTP>>> Exporter(5.68)
Net::SMTP>>> IO::Socket::INET6(2.71)
Net::SMTP>>> IO::Socket(1.36)
Net::SMTP>>> IO::Handle(1.34)
Net::SMTP=GLOB(0x1e0a920)<<< 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-2108164273 5RjAQr5ZFI284sDt1KWu
Net::SMTP=GLOB(0x1e0a920)>>> EHLO localhost.localdomain
Net::SMTP=GLOB(0x1e0a920)<<< 250-email-smtp.amazonaws.com
Net::SMTP=GLOB(0x1e0a920)<<< 250-8BITMIME
Net::SMTP=GLOB(0x1e0a920)<<< 250-SIZE 10485760
Net::SMTP=GLOB(0x1e0a920)<<< 250-STARTTLS
Net::SMTP=GLOB(0x1e0a920)<<< 250-AUTH PLAIN LOGIN
Net::SMTP=GLOB(0x1e0a920)<<< 250 Ok
Net::SMTP=GLOB(0x1e0a920)>>> STARTTLS
Net::SMTP=GLOB(0x1e0a920)<<< 220 Ready to start TLS
Net::SMTP::_SSL=GLOB(0x1e0a920)>>> EHLO localhost.localdomain
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250-email-smtp.amazonaws.com
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250-8BITMIME
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250-SIZE 10485760
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250-STARTTLS
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250-AUTH PLAIN LOGIN
Net::SMTP::_SSL=GLOB(0x1e0a920)<<< 250 Ok
Died at test_script.pl line 17.
请告诉我解决方案。
提前谢谢你!
【问题讨论】:
-
您的代码中没有任何错误处理。我猜在您发出
$smtp->mail(...)之前有些事情失败了,例如身份验证失败。请在您的代码中添加调试(即在调用Net::SMTP_auth->new时添加Debug => 1)并将完整的调试输出包含在您的问题中。 -
1) 为什么使用
Net::SMTP_auth而不是Net::SMTP?当前版本的Net::SMTP支持 SMTP AUTH。 2) 将,Debug=>1)添加到Net::SMTP构造函数(新)以获取SMTP 会话的记录。 -
@SteffenUllrich 感谢您的 cmets。我已将调试输出添加到问题中,请告诉我如何解决此问题
标签: perl email smtp amazon-ses smtp-auth