Send system emails using gmail as smtp server

I wrote before about sending system emails using sendmail as a smarthost. Here is an alternative approach using Gmail SMTP servers — often simpler to set up for home servers and small VPS.

The software that makes this easy is called ssmtp. It is a lightweight MTA that forwards mail to a configured SMTP relay, perfect for this use case.

Installation and configuration

Install ssmtp:

apt-get install ssmtp

Edit /etc/ssmtp/ssmtp.conf:

root=myAccount@gmail.com
mailhub=smtp.gmail.com:587
hostname=myHostname.com
UseSTARTTLS=YES
AuthUser=myAccount
AuthPass=myPassword
FromLineOverride=YES

And set your address in /etc/ssmtp/revaliases:

root:myAccount@gmail.com:smtp.gmail.com:587

That is it. From now on, system emails are delivered through your Gmail account. If you use two-factor authentication, generate an app-specific password instead of using your main password.

Enjoy!

One thought on “Send system emails using gmail as smtp server”

Leave a Reply

Your email address will not be published. Required fields are marked *