Sending mail from Raspbian using Gmail

Sources: Prepare Your Pi To Send Mail Through Gmail / Google 2-step verification and Send Mail with Gmail and sSMTP

First install basic tools:

sudo apt-get install ssmtp mailutils mpack

Next steps:
– create strong password (you can use: https://strongpasswordgenerator.com/)
– setup Google 2-step verification: https://www.google.com/landing/2step/
create Google App password: https://support.google.com/accounts/answer/185833

Edit configuration file:

sudo nano /etc/ssmtp/ssmtp.conf

comment out all using #, then add:

root=<your-gmail-account>@gmail.com

#GMAIL 
mailhub=smtp.gmail.com:587
hostname=<hostname>
AuthUser=<your-gmail-account>@gmail.com
AuthPass=<your-google-app-password>
useSTARTTLS=YES

TESTING

In your home folder create file body.txt (nano /body.txt) and add some text to it.

Send test mail using:

mail -s "Test mail subject" <your-gmail-account>@gmail.com < body.txt

Or:

echo "Test mail body." | mail -s "Test mail subject"<your-gmail-account>@gmail.com
Advertisements

One thought on “Sending mail from Raspbian using Gmail”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s