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:
defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile ~/.msmtp.log account gmail host smtp.gmail.com port 587 from email@example.com user firstname.lastname@example.org 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 email@example.com cat file.txt | msmtp -a default firstname.lastname@example.org
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" email@example.com echo 'Message' | mail -s "Subject" -A attachment.zip firstname.lastname@example.org echo 'Message' | sendmail email@example.com