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

Popular posts

Hipchat and Icinga

Hipchat Notify 2.0 Hipchat notification with API 2.0 to be used with ICINGA/Nagios Table of Contents Table of Contents Author Audience Introduction Ruby Script Script used on server Service notification Host notification Change in command.conf for Icinga server Example notification Roadmap Author Shubhamkr619@gmail.com Audience System Engineers and operation engineers Introduction Change the default mail notification of Icinga server to hipchat notification using ruby code. This will allow a single place of management of all the notification and alerts across organization. Let that be service,host or business level alerts all can be managed and monitored using hipchat and hubot will give certain advantage over traditional alerting system. Proactive and reactive alerting Managed monitoring Single place of all the alerts Better communication and collaboration Integration with multiple tools in CI cycle Jenkins Chef ...

Enter your email address: