5% assure discount from here only

Thursday, January 27, 2011

(17) How to send MAIL from perl script?

Solution :

There are so many ways to send MAIL from perl script. Out of them the simplest perl script is here :

To run this the only thing is required the CPAN module Mail::Sendmail.

Perl, being perl, provides the programmer with more than one ways to do same thing, sending email included.
Simple platform independent e-mail from your perl script. Only requires Perl 5 and a network connection.
Mail::Sendmail contains mainly &sendmail, which takes a hash with the message to send and sends it. It is intended to be very easy to setup and use.

After installing the module, you have to run this command on terminal:

service sendmail restart

use Mail::Sendmail;

%mail = ( To => 'you@there.com',
From => 'me@here.com',
cc => 'if any', # optional
bcc => 'if any' # optional
Message => "This is a very short message"
);

sendmail(%mail) or die $Mail::Sendmail::error;

print "OK. Log says:\n", $Mail::Sendmail::log;

No comments:

Post a Comment