Wednesday 19 August 2015

Send email from script

Install ssmtp:

    $ sudo apt-get install ssmtp

Edit the ssmtp config file:

    $ sudo vim /etc/ssmtp/ssmtp.conf

Enter this in the file:

root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password (create a app-specific password in google accounts)
FromLineOverride=YES
UseTLS=YES

Enter the email address of the person who will receive your email:

    $ ssmtp recepient_name@gmail.com

Now enter this:

To: recipient_name@gmail.com
From: username@gmail.com
Subject: Sent from a terminal!

Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.
(Notice the blank space between the subject and the body.)

To send the email: Ctrl + D

You can also save the text mentioned in Point 5 into a text file and send it using:

    $ ssmtp recipient_name@gmail.com < filename.txt

http://askubuntu.com/questions/12917/how-to-send-mail-from-the-command-line

No comments:

Post a Comment