Pages

Tuesday, October 27, 2009

Perl SendEmail

SendMail.pl file:

require "SendMail.pm";

# demo usuage
sendEmail("Sending Emailing from the linux box", "Files required: SendMail.pl and SendMail.pm. \n . \n - Harmeet");

sub sendEmail
{
my ($subject, $message) = @_;

# authenication data
$userid='';
$password="";
$authtype="AUTH PLAIN";

# from and to
$from=$userid;
$to='';

# declares new SendMail object
$sm = new SendMail("",port_number);
$sm->setAuth($authtype, $userid, $password);

#sender
$sm->From($from);

# subject
$sm->Subject($subject);

# to
$sm->To($to);

# content of the mail
$sm->setMailBody($message);

# checks is mail is sent
if ($sm->sendMail() != 0) {
print $sm->{'error'}."\n";
exit -1;
}

# if mail is sent
print "Mail Sent\n\n";
exit 0;
}



SendMail.pm file
http://www.tneoh.zoneit.com/perl/SendMail/download/
Beware that the latest solution is at the bottom. Just get the SendMail.pl and put it in the same folder

No comments:

Post a Comment