SASL is a generic mechanism for authentication used by several network protocols. Authen::SASL provides an implementation framework that all protocols should be able to share.
-------------------------------------------------
use Net::SMTP;
use Authen::SASL;
my $mailhost = "mail.fudan.edu.cn"; # the smtp host
my $mailfrom = 'lschen@fudan.edu.cn'; # your email address
my @mailto = ('032021157@fudan.edu.cn'); # the recipient list
my $subject = "Subject";
my $text = "Test mail sender,kasfasdfk\n.......";
$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);
# anth login, type your user name and password here
my $sasl =Authen::SASL->new(mechanism => 'LOGIN', callback=>{user => "lschen", pass => "********"} );
$smtp->auth($sasl);
foreach my $mailto (@mailto) {
# Send the From and Recipient for the mail servers that require it
$smtp->mail($mailfrom);
$smtp->to($mailto);
# Start the mail
$smtp->data();
# Send the header
$smtp->datasend("To: $mailto\n");
$smtp->datasend("From: $mailfrom\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
# Send the message
$smtp->datasend("$text\n\n");
# Send the termination string
$smtp->dataend();
}
--------------------------------------------------