Send email using gmail in Perl
March 22, 2012 § 2 Comments
Here’s sample code to send email via gmail smtp server, which uses TLS (transport layer security):
#!/usr/bin/perl -w
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
'smtp.gmail.com',
Hello => 'smtp.gmail.com',
Port => 587,
User => 'gmail userid',
Password=> 'gmail password');
$mailer->mail('from\@domain.com');
$mailer->to('targetuser\@userdomain.com');
$mailer->data;
$mailer->datasend("Subject:Email Subject");
$mailer->datasend("From:From Name<from\@domain.com>\n");
$mailer->datasend("To:targetuser\@userdomain.com");
$mailer->datasend("This is the email body");
$mailer->dataend;
$mailer->quit;
Nice idea, but I am getting:
Auth failed: 535 5.7.1 Please log in with your web browser and then try again. Learn more at
at mail.pl line 4.
Wow, fantastic blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your web site is
great, as well as the content!