MSMTP and Gmail

Email notification. Yes, this is one of the features that I need especially for a server. From time to time, it is nice to know the status of my server, important tasks that are being completed, etc. Also, if something fails, I would also like to know. I have been searching around and the only easiest to implement is msmtp. There is ssmtp, but for what I read online, it has been updated in a while. While msmtp is still getting updates.

It is not required, but I think it is better to create a new Gmail account with app password enabled for every instance that need to use your Gmail. If you are not familiar with the app password, follow this link to Google’s how-to.

Debian

Installing msmtp is pretty straight forward.

apt install msmtp

Once msmtp is installed, we need to create a file /etc/msmtprc with the following content.

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 protected]
user           [email protected]
password       yourAppPassword
account default : gmail

CentOS

In CentOS and similar, installing msmtp is very similar to Debian except the location of the ca-cert.

dnf install msmtp

Create the file /etc/msmtprc with the following content.

defaults
auth           on
tls            on
tls_trust_file /etc/pki/tls/certs/ca-bundle.crt
logfile        ~/.msmtp.log
account        gmail
host           smtp.gmail.com
port           587
from           [email protected]
user           [email protected]
password       yourAppPassword
account default : gmail

Testing

We installed msmtp and configured it. It is time to test it to make sure that it is working.

echo -e "Subject: Testing email from $HOSTNAME\n\nThis is a test email." | msmtp [email protected]

Check your receiving Gmail account that you received the test email.

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
colej
colej
11 months ago

works great with NUT! thx

1
0
Would love your thoughts, please comment.x
()
x