Reputation: 603
I am following a course of Perl and have received a task to send myself an email from perl@perlrocks using Mail::Sendmail module.
Though I have read the documentation, I still don't understand how to do it. For example, I use gmail as my normal email, should I configure gmail as the smpt protocol in the script? Could you please give me a hint on how to start?
Upvotes: 0
Views: 2231
Reputation: 34837
It depends on your environment. If you're running the script on a Linux server, just make sure the sendmail
utility is installed (most distributions have it pre-installed). If you're on a non-Linux machine, install a mailserver on it or use an external SMTP server.
Although this specific mail module does not support SMTP authentication, which most external SMTP servers (like Google/Gmail) do require. But if you have a mailserver that does always allow SMTP connections from the machine your Perl script runs on, it can be as simple as:
use Mail::Sendmail qw(sendmail %mailcfg);
%mail = ( To => '[email protected]',
From => '[email protected]',
Message => "Hello world!"
);
$mailcfg{smtp} = [qw(smtp.example.com)];
sendmail(%mail) or die $Mail::Sendmail::error;
That will set smtp.example.com
as e-mail server. (or you can skip that entire line if you do have a localhost mailserver, which is the default).
Upvotes: 1