Table of Contents

,

Send mail from raspberrypi using Gmail

1. Turn on 2-factor authentication in Google and generate the app password which will be used by the pi.

2. Install packages:

sudo apt-get install msmtp msmtp-mta mailutils

3. Put the following in /etc/msmtprc

# Generics
defaults
auth           on
tls            on
# following is different from ssmtp:
tls_trust_file /etc/ssl/certs/ca-certificates.crt
# user specific log location, otherwise use /var/log/msmtp.log, however, 
# this will create an access violation if you are user pi, and have not changes the access rights
logfile        ~/.msmtp.log

# Gmail specifics
account        gmail
host           smtp.gmail.com
port           587

from          root@raspi-buster
user           your-gmail-accountname@gmail.com
password       your-gmail-account-password

# Default
account default : gmail

4. Test

echo 'message' | mail -s "raspi-buster" destination-email-address@gmail.com

Tested on

See also

References