Perl Net::SMTP强制身份验证方法



我正在尝试使用PerlNet::SMTP和身份验证方法发送邮件,而不是默认选择的GSSAPI(例如强制PLAIN(。

我试过:

my $smtp;
$smtp = Net::SMTP::SSL->new($host, Port => $port);
$smtp->auth($user, $passwd);

并将最后一行替换为:

$smtp->auth('PLAIN', $user, $passwd);

或将具有选定机制Authen::SASL对象传递给$smtp->auth()。以上都不起作用 - 调试(和邮件服务器日志(说它仍然尝试AUTH GSSAPI.

有谁知道如何在Net::SMTP中正确强制身份验证方法?

我的 Perl 版本是来自 Debian 8 的 5.20.2-3+deb8u8,软件包版本:

  • 网络::SMTP - 2.33
  • 网络::
  • SMTP::SSL - 1.01
  • 身份验证::SASL - 2.16

Net::SMTP版本高于3.00

Net::SMTP以上版本 3:
* 不会覆盖auth方法
Authen::SASL参数中的机制* 支持STARTTLS和 SMTP

use Net::SMTP;
use Authen::SASL;
my($host, $user, $pass) = ('...','...','...'); # fill correct data
my $smtp = Net::SMTP->new( $host, SSL=>1, Debug => 1 ); # SSL=>1 - use smtps
$smtp->auth(
Authen::SASL->new(
mechanism => 'PLAIN LOGIN',
callback  => { user => $user, pass => $passwd }
)
);

Net::SMTP版本低于3.00

Net::SMTP版本 2.31_1(libnet 中最新的 3.00 之前版本(使用回复中列出的机制覆盖了Authen::SASL中的机制EHLO。 请在下面找到我的丑陋修复。

use Net::SMTP::SSL;
use Authen::SASL;
my ( $host, $port, $user, $pass ) = ( '...', '...', '...', '...' );    # fill correct data
my $smtp = Net::SMTP::SSL->new( $host, Port => $port, Debug => 1 );
my $auth = Authen::SASL->new(
mechanism => 'PLAIN LOGIN',
callback  => { user => $user, pass => $passwd }
);
{
no warnings 'redefine';
my $count;
local *Authen::SASL::mechanism = sub {
my $self = shift;
# Fix Begin
# ignore first setting of mechanism
if ( !$count++ && @_ && $Net::SMTP::VERSION =~ /^2./ ) {
return;
}
# Fix End
@_
? $self->{mechanism} = shift
: $self->{mechanism};
};
$smtp->auth($auth);
}

需要修复的代码 - Net::SMTP 2.31_1 来自 libnet 1.22_01

sub auth {
my ($self, $username, $password) = @_;
...
my $mechanisms = $self->supports('AUTH', 500, ["Command unknown: 'AUTH'"]);
return unless defined $mechanisms;
my $sasl;
if (ref($username) and UNIVERSAL::isa($username, 'Authen::SASL')) {
$sasl = $username;
$sasl->mechanism($mechanisms); # <= HERE Authen::SASL mechanism overwrite 
}

相关内容

最新更新