且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Perl TLS SMTP发送在身份验证步骤失败

更新时间:2023-12-04 23:25:22

最终对我有用的是使用 use Authen::SASL qw(Perl):

What finally worked for me was using use Authen::SASL qw(Perl):

use strict ;
use warnings ;

use Net::SMTP
#use Authen::SASL;         # This did NOT work.
use Authen::SASL qw(Perl); # This DID work.

my $smtp_server = 'smtp.example.com';
my $principal   = 'myusername';
my $password    = 'secretsecretsecret';

my $from        = 'myname@example.com';
my $to          = 'afriend@example.net';
my $subject     = 'Hello friend';
my $body        = 'Give me a call when you can.';

my $mailer = Net::SMTP->new($smtp_server, 'SSL' => 1, 'Port' => 465, 'Debug' => 1);
if (!$mailer) { die $@ ; }

if (!$mailer->auth($principal, $password)) {
    print "error authenticating; status is '" . $mailer->status() . "'\n";
    print "error authenticating; message is '" . $mailer->message() . "\n'";
    exit 1;                                                                                                                  
}

$mailer->mail($from) ;
$mailer->to($to) ;
$mailer->data();
$mailer->datasend("To: $to");
$mailer->datasend("\n");
$mailer->datasend("Subject: $subject");
$mailer->datasend("\n");
$mailer->datasend($body);
$mailer->dataend();
$mailer->quit;

这就引出了一个问题:为什么 使用 Authen::SASL; 不起作用.

This begs the question as to why use Authen::SASL; did not work.