This SMTP application works the same way on Raspbian 10 (Buster).

sudo apt-get install msmtp msmtp-mta -y
sudo nano /etc/msmtprc

Copy and paste this content to the file:

auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
account gmail
port 587
password password
account default : gmail

Using your real password is not the best way for two reasons. First, it will be stored as plain text and other users of your server can read it. Second, you have to go into your configuration account and allow “less secure apps” [Link].

You can create an API Password (one password exclusive for this application) in your Google account configuration, copy, and paste the random password in the MSMTP.

Steps (the links are shortcuts, if not working just follow the steps):

  • Enter your Google account settings [Link].
  • Select¬†Security [Link].
  • In Signing in to Google enable 2-Step Verification [Link].
  • Select App Passwords [Link].
  • Select the app and device you want to generate the app password for.
  • Click Generate.
  • Copy the password that may log line this: mssl uemq sabi fjbc.
  • Then paste in the MSMTP configuration file.

This App Password procedure might be the same if you want to user Sendmail or Postfix as Google relay.

All the e-mails sent using the Google server will have the sender e-mail the same as your account e-mail.

Test your configuration:

(echo "Subject: Test"; echo 'Body of the email') | msmtp
cat file.txt | msmtp -a default

Note: -a followed by the name of the configuration name will select what configuration file (server, credentials, etc) will be used.

Also, install the mail tools and test them:

sudo apt-get install mailutils -y
echo 'Message' | mail -s "Subject"
echo 'Message' | mail -s "Subject" -A
echo 'Message' | sendmail

2 Replies to “Using MSMTP with Google SMTP Relay on Ubuntu 20.04”

Comments are closed.