Use the Net::SMTP module to send an email through an ms exchange smtp server
上一篇 /
下一篇 2008-11-12 14:02:02
/ 个人分类:Perl
use Net::SMTP;
my $smtpSer = 'mailhost';
my $from ='from@xxx.com';
my $to ='to@xxx.com';
my $subject = 'Test';
my $body = "A simple test message";
$smtp = Net::SMTP->new($smtpSer);
$smtp->mail($ENV{USER});
$smtp->to($to);
$smtp->data();
$smtp->datasend("From: $from\n");
$smtp->datasend("To: $to\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("Body: $body\n");
$smtp->dataend();
$smtp->quit;
##############################################################################
perldoc Net::SMTP for more details
If you need authentication (ie. server does not relay) then substitute Net::SMTP for Net::SMTP_auth. The trick to make this two work together is to create a email message with MIME::Lite (you can add attachments, use html or text) then convert the MIME::Lite object into a string (there is a method to do it within the module) then using the datasend(string) method from Net::SMTP your email will be ready to go.
收藏
举报
TAG:
Perl
Net::SMTP
send
email