Send email using gmail in Perl

Author - Webner
2.03.2015
|
0 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;

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *