Monthly Archives: October 2015

Raspberry Pi – Send Mails

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:

root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username@gmail.com
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:

send_mail_raspberry_authentication_failed

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:

send_mail_raspberry_access_less_secure_apps

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 🙂

Sources:

http://www.raspberry-projects.com/pi/software_utilities/email/ssmtp-to-send-emails

http://ozzmaker.com/2012/12/03/send-email-from-the-raspberry-pi-or-linux-command-line-with-attachments/

http://ubuntuforums.org/showthread.php?t=1691878

https://support.google.com/accounts/answer/6010255?hl=en

https://www.google.com/settings/security/lesssecureapps

Tagged , ,