Scripting >> Perl >> How to send mail using Net : : SMTP from ActivePerl distribution

#!/usr/local/ActivePerl-5.6/bin/perl -w # assumes ActivePerl 5.6 installed at above directory use Net::SMTP; $smtp = Net::SMTP->new('smtpserver' # smtp host Hello => 'mydomain.com', # smtp host's domain Timeout => 30, # connection timeout Debug => 1, # debuggin on i.e. verbose ); $smtp->mail('sender@testserver'); # sender $smtp->to('recipient@somedomain.com'); # recipient $smtp->data(); # start of message $smtp->datasend("To: recipient\@somedomain.com\n"); # sender - can be fake $smtp->datasend("Subject: Test subject\n"); # message title $smtp->datasend("\n"); # required $smtp->datasend("line 1\n"); # actual message start $smtp->datasend("line 2\n"); $smtp->dataend(); # message end $smtp->quit(); # close SMTP connection