在DigitalOcean上我有一个vps在box.emailserver.com上运行MIAB(“Mail-in-aBox”),在appserver.com上运行另一个vps上的web应用服务器。
我想使用Perl脚本从网络应用发送电子邮件。
我正在为这两个域名使用MIAB DNS服务器。使用MIAB服务器,我可以使用我的Mac Mini“Mail”应用程序发送和接收电子邮件,以便它运行良好。
我编辑了一个perl脚本I found on CPAN,它试图验证用户并从appserver.com发送一封简单的电子邮件,但它没有通过auth阶段。我收到这个错误:
发送电子邮件时出错:AUTH:命令未知:'AUTH'
任何人对我做错了什么有任何想法?
这是Web应用服务器上的脚本,来自MIAB的mail.log,以及运行时脚本输出的内容:
#!/usr/bin/perl
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTPS;
use Try::Tiny;
my $transport = Email::Sender::Transport::SMTPS->new(
host => 'box.emailserver.com',
ssl => 'starttls',
sasl_username => 'hostmaster@emailserver.com',
sasl_password => 'xxxx',
debug => 1, # or 1
);
use Email::Simple::Creator; # or other Email::
my $message = Email::Simple->create(
header => [
From => 'hostmaster@emailserver.com',
To => 'bill@my.com',
Subject => 'appserver.com perl test',
],
body => 'This is the test.',
);
try {
sendmail($message, { transport => $transport });
} catch {
die "Error sending email: $_";
};
MIAB mail.log:
Apr 16 13:17:10 box postfix/submission/smtpd[31729]: connect from appserver.com[45.55.229.99]
Apr 16 13:17:10 box postfix/submission/smtpd[31729]: lost connection after EHLO from appserver.com[45.55.229.99]
Apr 16 13:17:10 box postfix/submission/smtpd[31729]: disconnect from appserver.com[45.55.229.99]
appserver.com perl脚本输出
root@appserver:/usr/lib/cgi-bin# perl test6.pl
Net::SMTPS>>> Net::SMTPS(0.06)
Net::SMTPS>>> IO::Socket::IP(0.37)
Net::SMTPS>>> IO::Socket(1.38)
Net::SMTPS>>> IO::Handle(1.35)
Net::SMTPS>>> Exporter(5.72)
Net::SMTPS>>> Net::SMTP(3.10)
Net::SMTPS>>> Net::Cmd(3.10)
Net::SMTPS=GLOB(0x33b7958)<<< 220 box.emailserver.com ESMTP Hi, I'm a Mail-in-a-Box (Ubuntu/Postfix; see https://mailinabox.email/)
Net::SMTPS=GLOB(0x33b7958)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x33b7958)<<< 250-box.emailserver.com
Net::SMTPS=GLOB(0x33b7958)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x33b7958)<<< 250-SIZE 134217728
Net::SMTPS=GLOB(0x33b7958)<<< 250-VRFY
Net::SMTPS=GLOB(0x33b7958)<<< 250-ETRN
Net::SMTPS=GLOB(0x33b7958)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x33b7958)<<< 250-ENHANCEDSTATUSCODES
Net::SMTPS=GLOB(0x33b7958)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x33b7958)<<< 250 DSN
Error sending email: failed AUTH: Command unknown: 'AUTH'
Trace begun at /usr/local/share/perl/5.22.1/Email/Sender/Transport/SMTPS.pm line 98
Email::Sender::Transport::SMTPS::_throw('Email::Sender::Transport::SMTPS=HASH(0x24d8b80)', 'failed AUTH', 'Net::SMTPS=GLOB(0x33b7958)') called at /usr/local/share/perl/5.22.1/Email/Sender/Transport/SMTPS.pm line 71
Email::Sender::Transport::SMTPS::smtpclient('Email::Sender::Transport::SMTPS=HASH(0x24d8b80)') called at /usr/local/share/perl/5.22.1/Email/Sender/Transport/SMTPS.pm line 107
Email::Sender::Transport::SMTPS::send_email('Email::Sender::Transport::SMTPS=HASH(0x24d8b80)', 'Email::Abstract=ARRAY(0x3023ae0)', 'HASH(0x3023ca8)') called at /usr/local/share/perl/5.22.1/Email/Sender/Role/CommonSending.pm line 45
Email::Sender::Role::CommonSending::try {...} at /usr/share/perl5/Try/Tiny.pm line 92
eval {...} at /usr/share/perl5/Try/Tiny.pm line 83
Try::Tiny::try('CODE(0x307b370)', 'Try::Tiny::Catch=REF(0x3023d38)') called at /usr/local/share/perl/5.22.1/Email/Sender/Role/CommonSending.pm line 58
Email::Sender::Role::CommonSending::send('Email::Sender::Transport::SMTPS=HASH(0x24d8b80)', 'Email::Abstract=ARRAY(0x3023ae0)', 'HASH(0x3069a30)') called at /usr/local/share/perl/5.22.1/Email/Sender/Simple.pm line 119
Email::Sender::Simple::send_email('Email::Sender::Simple', 'Email::Abstract=ARRAY(0x3023ae0)', 'HASH(0x3023cf0)') called at /usr/local/share/perl/5.22.1/Email/Sender/Role/CommonSending.pm line 45
Email::Sender::Role::CommonSending::try {...} at /usr/share/perl5/Try/Tiny.pm line 92
eval {...} at /usr/share/perl5/Try/Tiny.pm line 83
Try::Tiny::try('CODE(0x3023b58)', 'Try::Tiny::Catch=REF(0x3005228)') called at /usr/local/share/perl/5.22.1/Email/Sender/Role/CommonSending.pm line 58
Email::Sender::Role::CommonSending::send('Email::Sender::Simple', 'Email::Simple=HASH(0x3004f88)', 'HASH(0x3004ee0)') called at /usr/share/perl5/Sub/Exporter/Util.pm line 18
Sub::Exporter::Util::ANON('Email::Simple=HASH(0x3004f88)', 'HASH(0x3004ee0)') called at test6.pl line 26
main::try {...} at /usr/share/perl5/Try/Tiny.pm line 92
eval {...} at /usr/share/perl5/Try/Tiny.pm line 83
Try::Tiny::try('CODE(0x2fd50b0)', 'Try::Tiny::Catch=REF(0x2f96d08)') called at test6.pl line 29
答案 0 :(得分:1)
Net::SMTPS=GLOB(0x33b7958)<<< 220 box.emailserver.com ESMTP Hi, I'm a Mail-in-a-Box (Ubuntu/Postfix; see https://mailinabox.email/)
Net::SMTPS=GLOB(0x33b7958)>>> EHLO localhost.localdomain
Net::SMTPS=GLOB(0x33b7958)<<< 250-box.emailserver.com
Net::SMTPS=GLOB(0x33b7958)<<< 250-PIPELINING
Net::SMTPS=GLOB(0x33b7958)<<< 250-SIZE 134217728
Net::SMTPS=GLOB(0x33b7958)<<< 250-VRFY
Net::SMTPS=GLOB(0x33b7958)<<< 250-ETRN
Net::SMTPS=GLOB(0x33b7958)<<< 250-STARTTLS
Net::SMTPS=GLOB(0x33b7958)<<< 250-ENHANCEDSTATUSCODES
Net::SMTPS=GLOB(0x33b7958)<<< 250-8BITMIME
Net::SMTPS=GLOB(0x33b7958)<<< 250 DSN
根据EHLO命令的输出,服务器不支持任何类型的身份验证。如果它会有像250-AUTH LOGIN PLAIN ...
那样的行,即声明支持AUTH命令并显示支持哪种认证方法的行。但由于没有这样的线路,服务器不支持身份验证。
如果要使用身份验证,则需要在服务器设置中修复此问题。虽然我在MIAB的设置指南中找不到关于它的信息,但它使用支持身份验证的Postfix,并且在线有各种描述该过程的教程。但是,对于此服务器设置的任何问题可能都是在serverfault.com上的主题。
答案 1 :(得分:1)
此处或其他地方的说明都不适用于我,因此我使用Net :: SMTP制作了自己的解决方案。我有一个Mail-In-A-Box在Namecheap上成功运行,并使用Perl脚本提供完整的STARTTLS支持。电子邮件通过Gmail的垃圾邮件文件夹,通过所有真实性测试。完全配置mailinabox服务器后,可以使用此脚本通过SMTP发送电子邮件。
#!/usr/bin/perl
use warnings;
use strict;
use Net::SMTP;
use Authen::SASL;
my $host = 'box.yoursite.com'; #server1.yoursite.com if on namecheap
my $port = 587;
my $username = 'you@yoursite.com';
my $password = 'yourpassword';
my $sendto = 'your@friend.com';
my $smtp = Net::SMTP->new(
$host,
Port => $port,
SSL => 0, #No SSL on initial handshake.
Timeout => 10,
Debug => 1
);
#Postfix has no AUTH option until STARTTLS.
$smtp->starttls();
$smtp->auth($username, $password);
$smtp->mail($username);
if ($smtp->to($sendto)) {
$smtp->data();
$smtp->datasend("From: $username\n");
$smtp->datasend("To: $sendto\n");
$smtp->datasend("Subject: Test message\n");
$smtp->datasend("\n");
$smtp->datasend("The test works!\n");
$smtp->dataend();
} else {
print "Error: ", $smtp->message();
}
$smtp->quit;
一些注意事项:
SSL=>0
)的情况下执行,一旦启动,就可以建立STARTTLS连接。因此,此初始EHLO握手无法从mailinabox服务器返回250-AUTH
响应,但将SMTP连接构造函数升级到STARTTLS($smtp->starttls()
)成功返回250-AUTH PLAIN LOGIN
,此时,您可以按正常方式继续使用SMTP服务器进行身份验证。