Sending Mail Through Gmail with Perl

We talked about some of the benefits of setting up an email server in Linux and how you can use python to send email. Now we are going to look at how you can send email from Perl.

The Code

use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
    'smtp.gmail.com',
    Hello   =>      'smtp.gmail.com',
    Port    =>      587,
    User    =>      'username',
    Password=>      'password');
$mailer->mail('from@domain.com');
$mailer->to('to@domain.com');
$mailer->data;
$mailer->datasend("Sent from perl!");
$mailer->dataend;
$mailer->quit;