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:
[code lang=”bash”]sudo apt-get install ssmtp mailutils[/code]

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

Then, allow access from less secure apps to created Gmail account and enable one-time sign-in for new app without captcha. It’s strongly recommended not to use your private account for that purpose!

And send emails:
[bash]echo "email body" | mail -s "Test email from "`hostname`[/bash]

VoilĂ !

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