Use Net::smtp_auth to send messages in Perl.

Source: Internet
Author: User

1, send mail on an SMTP server that does not require authentication
#!/usr/bin/perl-w
Use NET::SMTP;
$SMTP = net::smtp->new ($mail _server); #邮件服务器地址
$smtp->mail ($send _user); #发件人
$smtp->to ($recv _user); #收件人
$SMTP->data ();
$smtp->datasend ("Subject: Test subject/n"); #主题
$SMTP->datasend ("n");
$smtp->datasend ("A Simple test message tests in English mix/n"); #消息内容
$SMTP->dataend ();
$SMTP->quit;
2, send mail on an SMTP server that requires authentication
#!/usr/bin/perl-w
Use strict;
Use Net::smtp_auth;
My $mailhost = ' mail.abc.cn ';
My $mailfrom = ' 120@abc.cn ';
My @mailto = (' aaa@163.com ',
' bbb@163.com ');
My $user = ' 120@abc.cn ';
My $passwd = ' 123456 ';
My $subject = ' hello ';
#my $text
My $f _list = '/home/sysadmin/scp.log ';
Open (FILE, $f _list) or die "Can not open list file/n";
Undef $/;
my $text =;
My $smtp = Net::smtp_auth->new ($mailhost, timeout=>120, Debug => 1) or die "error./n";
$smtp->auth (' LOGIN ', $user, $passwd);
foreach my $mailto (@mailto) {
$SMTP->mail ($mailfrom);
$SMTP->to ($mailto);
$SMTP->data ();
$smtp->datasend ("to: $mailto/n");
$smtp->datasend ("From: $mailfrom/n");
$smtp->datasend ("Subject: $subject/n");
$SMTP->datasend ("n");
$smtp->datasend ("$text/n/n");
$SMTP->dataend ();
}
$SMTP->quit;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.