Skip to main content

Send mail via SMTP using PERL

Send Mail to gmail account with perl

Installation of Send::SMTP::Gmail: 

In order to send mail via Gmail, you need to have TLS verification. Having TLS and Installation of perl package Send::SMTP::Gmail is covered in brief. 

For Ubuntu: 

sudo apt-get install openssl libnet-ssleay-perl  libcrypt-ssleay-perl

For RedHat/Fedora/CentOs:

yum  install  perl-IO-Socket-SSL  perl-Digest-HMAC  perl-TermReadKey  perl-MIME-Lite  perl-File-LibMagic  perl-IO-Socket-INET6 perl-Net-SSLeay perl-Crypt-SSLeay perl-Email-Send

Usages: 

Following method is used to send mail and attachment in it. Please read it and post your comments.


sub sendMail
{
        use Email::Send::SMTP::Gmail;
        my $to=shift;
        my $cc=shift;
        my $subject=shift;
        my $body=shift;
        
        my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
                                                -login=>'yourUser@eko.co.in',
                                                -pass=>'passwd',
                                                -port=>587,
                                                -debug=>1);
        
         $mail->send(-to=>"$to",
                        -cc=>"$cc",
                            -subject=>$subject,
                            -verbose=>'1',
                            -body=>$body
                           );
         #-attachments=>'full_path_to_file'
        $mail->bye;


}

Comments

Enter your email address: