All posts for the month July, 2017

I recently reinstalled my Ubuntu server (16.04 LTS) and wanted to set up the customary unix mail handing stuff so that my cron, temperature monitoring, and hard drive monitor scripts could automatically email me of anything went wrong. In the past I’ve used mandrill and sparkpost for this, but free services like these keep getting more and more difficult and persnickety to use, most-recently demanding things like opt-out/unsubscribe links in the emails and adding a privacy policy to the website (despite there not actually _being_ any website). So I wanted to see if it was easy to send email via Gmail’s SMTP interface.

I followed two nearly-identical guides:

Basically, you need to install the ssmtp package, then edit the ssmtp.conf configuration file:

sudo apt-get install ssmtp

sudo vim /etc/ssmtp/ssmtp.conf

# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named

# Where will the mail seem to come from?

# The full hostname

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address

If you have two-factor (2FA) authentication set up for your Google account, you need to create an "app password" for this "device". Visit this page to create an app password that doesn't use 2FA auth:

However, there is a problem with those two guides, specifically in the hostname= line. If you put your actual email address as the hostname entry, then google will complain when you try to connect. You can use this test command to see what is going on:

$ echo "Hello 1" | sudo ssmtp -vvv
[< -] 220 ESMTP j76sm1853421ioi.14 - gsmtp
[->] EHLO
[< -] 501 5.5.4 j76sm1853421ioi.14 - gsmtp
ssmtp: Cannot open

What you need to do is to set hostname=localhost in the ssmtp.conf file. Then it should work fine.