How to Setup SMTP and Send Email Using Raspberry Pi

Assalamualaikum..

In order for the Raspberry Pi to send an email from the command line you need to install packages on the Raspberry. You are going to need the following packages

Installing

sudo apt-get install ssmtp
sudo apt-get install mailutils

Now edit the SSMTP configuration file

sudo nano /etc/ssmtp/ssmtp.conf

It needs to include this:

root=your_email@gmail.com
mailhub=smtp.gmail.com:587
hostname=hw0rkp1
AuthUser=your_email@gmail.com
AuthPass=your_password
AuthLogin=YES
FromLineOverride=YES
UseSTARTTLS=YES

Save and exit

Test Sending an Email

echo "Hello world email body" | mail -s "Test Subject" recipientname@domain.com

Some of you may get ERROR:
mail: cannot send message: Process exited with a non-zero status status

Solution:
There will be multiple solutions for this. Some user they may need to change their password. Other just need to change their port from 587 to 465. For me, I just enable Access for less secure apps. Here the link https://www.google.com/settings/security/lesssecureapps

Sending a File

Install mpack

sudo apt-get install mpack

To send a file

mpack -s "Test" /home/pi/some_folder/somefile.ext recipientname@domain.com

 

wassalam..

Advertisements
This entry was posted in Linux, Raspberry Pi and tagged , , . Bookmark the permalink.