Tuesday, April 16, 2013

Mail sending via perl


vim mail.pl
#!/usr/bin/perl -w
use strict;
use Mail::Sender;
my $filename = $ARGV[0];
my $smtp = “192.168.1.1″;
my $subj = “Hello”;
my $toaddr = ‘totest@test.com;
my $fromaddr = ‘fromtest@test.com’;
my $body = “Hello Administrator, Attached is the report. Thank you.”;

my $sender = new Mail::Sender {smtp => $smtp, from => $fromaddr};
$sender->MailFile({
to => $toaddr,
subject => $subj,
file => $filename,
msg => $body,
});
if( $Mail::Sender::Error) {
print “Error sending mail: $Mail::Sender::Error \n”;
} else { print “Sent ok to $toaddr $Mail::Sender::Error \n”; }

perl mail.pl <attach file>

No comments:

Post a Comment