Sending emails from command-line using Gmail & SSMTP

I wanted to send email reports from my computers. For that, the easiest is to create additional Gmail account (so your private email is safe) and set-up SSMTP:

sudo apt-get install ssmtp mailutils mpack

Configure SSMTP: comment all lines in /etc/ssmtp/ssmtp.conf and add at the end (replacing HOSTNAME/USER/PASSWORD with your info):

hostname=HOSTNAME 
mailhub=smtp.gmail.com:587
AuthUser=USER@gmail.com
AuthPass=PASSWORD
FromLineOverride=YES
UseSTARTTLS=YES

Then, allow access from less secure apps to created Gmail account. It’s strongly recommended not to use your private account for that purpose!

And send emails:

echo "email body" | mail -s "Test email from "`hostname` SOMEUSER@gmail.com

Voilà!

Note, this works perfectly fine in Ubuntu, as well as in Raspberry Pi.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s