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

Allowing users to have ssh access

Allowing users to have ssh access Hi Readers, It is one of the tasks we need to complete in order to allow users to log-in into your server without compromising your security. We are going to accomplish the following tasks, 1.) Allow the users for given domain only 2.) Must allow access to a given domain 3.) Block access for a specific domain. These questions are asked in RedHat certification examination RHCE6 We are going to complete the above mention task using iptables To give proper example we are taking 192.168.20.0/255.255.255.0 as our domain and 192.168.21.0/255.255.255.0 as other domain. Assuming that your system is a fresh installation we can remove all rules previously applied. # iptables -F  The above mention command will flush all the previously applied rules. Insert a rule in your input chain by below mention command, # iptables -I INPUT -s <ip of your domain>/<subnet mask> -p <protocal tcp/udp> --dport <port> -...

Using Flash in your HTML

Edit your Publish settings for Flash SWFs and HTML to reflect how you want your Flash SWF to appear in your web page. Export your Flash movie as HTML. Locate your HTML file on your computer, right-click, and select "Open With". Choose either NotePad or another text editor. Copy the source code from the HTML file. Paste it into your web page's source code in the appropriate location where you want your SWF file to display. Edit the file path to reflect the location of the SWF file on your web server, and upload both your HTML and SWF file to the appropriate directories on your server. ( Note:  this also applies if you're using PHP, JSP, ASP, CGI, or other web page extensions.) Your code should look something like this: <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="320" HEIGHT="240" id="You...

Change password of mysql users

Change MySQL user's password in bulk Sometimes we need to change the password of mysql users at bulk. Lets say your company has fired a group of peoples or dissolved a project. This requirement can be supplied as : We can achieve the same by changing the password field in mysql.user table. Password() is a predifined method in mysql which generates encrypted value of a certain string. host update mysql.user set password = PASSWORD("passwd") where host IN (<Comma separated list of HostName/IP>); user update mysql.user set password = PASSWORD("passwd") where user IN (<Comma separated list of ‘user’@’host’>);

Hubot and Hipchat

Many of us have struggle with concept of L1, and L2 support and maintenance which can be very expensive and transitioning is a living hell. What we wish is the ability for both of them to work together and make a smooth transition. So I have started to think it would be cool to make this happen for a organization which runs 1200+ servers and have teams to support product and infra both. The Idea was to start with collaboration between teams which can be extended to request and support basis. To extend it further we discovered  that product team works for 24x7 and infra team is 18x7. Now it is important to design it in a way that product team can manage it 24x7 with minimum and no help from infra team(L2).  Solution: Solution was to use a collaboration tool which supports API for our tools to maintain alert level. For that please refer my previous blog describing configuration of Icinga and Hipchat. Next logical step is to configure hipchat to support robot system ...

Using except command with bash

1.Use the interpreter for bash at first line . #!/bin/bash 2. Use variables as per requirement and pass it to except if needed. HOST="localhost" USER="chitti" PASS="123" CMD=$@ 3. Use expect script as required. XYZ=$(expect -c " spawn ssh $USER@$HOST expect \"password:\" send \"$PASS\r\" expect \"\\\\$\" send \"$CMD\r\" expect -re \"$USER.*\" send \"logout\" ") 4.Print the result of except using echo like echo "${XYZ}"

Enter your email address: