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?
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 => 'you@example.com',
From => 'me@example.com',
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.