cron send email via gmail

Published on:

Works with gmail as well as yahoo. Pretty much same settings.

In the end I used sSMTP. It's far, far simpler than either Postfix or sendmail and does the job beautifully.

For future reference, here's how to use sSMTP to with Yahoo Mail (don't worry, it's far less complex than it looks):

Use Synaptic to download ssmtp. Alternatively you could run sudo apt-get install ssmtp.

Open the config file at /etc/ssmtp/ssmtp.conf.

Make the config look like this:

Create the cert.pem file with OpenSSL. I used the command openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 9999 -nodes (more info here). You can stick the file anywhere, but I just chucked it in ~/. Wherever you put it, make sure you point the 'TLS_CA_File=' line in ssmtp.conf to the correct location.

Open the file /etc/ssmtp/revaliases and add the line [yourPCUsername]:[] If you're running as root, I would think you need to add another line replacing you name with 'root'.

That's it, you're good to go! To test, the easiest way (IMO) is to create a file with the following in it:

To: []
From: "whateverYaWant" <[]>
Subject: Some Notifying Email
MIME-Version: 1.0
Content-Type: text/plain

Body of your email goes here! Hello world!
Save and close the file, then (to check you don't have the real sendmail installed, run sendmail -V - it should say 'sSMTP') run cat fileWithEmailInIt.txt | sendmail -i -t. Then wait a few seconds (10-30) and check your email!
Obviously, replace [] with your email (without the brackets) and [yourRealYahooPassword] with your Yahoo Mail password (again, without the brackets).