Hello everyone, today I want to show you how to setup your Raspberry Pi to send mails via Googles SMTP server (smtp.gmail.com). I struggled a bit with Googles security settings and wanted to let you know how to solve the problems I encountered easily.
Before we begin you should update your Raspberry Pi:
sudo apt-get update
Next install ssmtp and mailutils:
sudo apt-get install ssmtp sudo apt-get install mailutils
Next we will save the current default ssmtp.conf Configuration file:
sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.old
Now we will create a new ssmtp.conf Configuration file:
sudo nano /etc/ssmtp/ssmtp.conf
Now have a look at the Configuration below and replace username and password with your Account data:
email@example.com mailhub=smtp.gmail.com:465 rewriteDomain=gmail.com AuthUserfirstname.lastname@example.org AuthPass=password FromLineOverride=YES UseTLS=YES
Important: If your password contains the character # your Configuration will not work since the character # is used to define comments in the Configuration file. (Source: http://ubuntuforums.org/showthread.php?t=1691878)
Now run the below command to send a mail via ssmtp:
ssmtp <RecipientMailAddress> Subject: <YourSubject> <YourMailText>
or you can use the below command to send a mail via mailutils:
echo "<YourMailText>" | mail -s "<YourSubject>" <RecipientMailAddress>
When you run the above ssmtp command to send your mail you will probably receive an error message like shown in the below screenshot:
The error “ssmtp: Authorization failed (534 5.7.14 …” means that the security settings of your Google Mail Account do not allow ssmtp to send mails.
To solve this problem you need to alter the security settings of your Google Mail Account by turning on the “Access for less secure apps” setting.
You can find this setting here: https://www.google.com/settings/security/lesssecureapps
The settings page should now look like this:
Now try again to send a mail and it should work now without problems.
Well, that´s it. You should now be able to send mails from your Raspberry Pi.
I hope you liked my post and I hope to see you again next time 🙂