Perl – How to send email to the Gmail account using SMTP and Perl

emailgmailperlsmtp

I don't want to use sendmail to send an email but would prefer to use SMTP. How can I use Perl to send an email to my GMAIL account?

Best Solution

personally I would suggest you to use my module Email::Send::SMTP::TLS which works pretty well through the TLS of Google Mail.

Thanks.

use Email::Send;

my $mailer = Email::Send->new( {
    mailer => 'SMTP::TLS',
    mailer_args => [
        Host => 'smtp.gmail.com',
        Port => 587,
        User => 'username@gmail.com',
        Password => 'password',
        Hello => 'fayland.org',
    ]
} );

use Email::Simple::Creator; # or other Email::
my $email = Email::Simple->create(
    header => [
        From    => 'username@gmail.com',
        To      => 'to@mail.com',
        Subject => 'Subject title',
    ],
    body => 'Content.',
);

eval { $mailer->send($email) };
die "Error sending email: $@" if $@;