Friday, January 16, 2026

In Praise Of msmtp - Painless Email Setup For Your AWS Linux Box

I recently kicked off a nano-sized AWS server to run a cron job. Out of the box, the server doesn't support sending email.

Back in the day, a local instance of sendmail would gladly deliver email on your behalf. This made sending email easy. A bit too easy, in fact, as it opened the door for spammers to do their thing. The feature that made this possible, and turned into a nightmare, was that email systems would simply trust the sender.

These days, you can still have sendmail deliver mail on your behalf, but most servers will reject it as they have no reason to trust the identity of your server.

In the AWS world, the next step is usually to turn to SES - Amazon's Simple Email Service. That is, you'd instruct the Linux box to deliver the messages to SES, and SES would manage matters of trust.

Using SES isn't hard, but I was curious if there was a lighter weight solution. A little searching turned up: msmtp.

msmtp is a lightweight mail delivery agent that will securely hand off messages to another server for delivery. In my case, it will deliver messages to my Google Workspace account, which will forward the message on to the recipient. Configuration is simple and the software has few dependencies.

For a full walkthrough of how to set this up, check out this informative post: Send emails from your terminal with msmtp . For a more terse setup description, check out this Gemini Conversation. To skip all the fluff and see the install recipe, check out the code below.

If you're on a Linux box and just want email to work, msmtp is your friend.

Setup Recipe

# 1. Install msmtp and the mail interface
sudo apt-get update && sudo apt-get install -y msmtp msmtp-mta bsd-mailx

# 2. Generate a password using Google's App Password facility

# 3. Create the global configuration file
cat <EOF | sudo tee /etc/msmtprc
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        /var/log/msmtp.log

account        gmail
host           smtp.gmail.com
port           587
from           ben@super-cool-company.com
user           ben@super-cool-company.com
password       super-secret-unguessable-password

account default : gmail
EOF

# 4. Setup log file and secure the configuration (600 permissions are required)
sudo touch /var/log/msmtp.log && sudo chmod 666 /var/log/msmtp.log
sudo chmod 600 /etc/msmtprc

# 5. Link the 'mail' command to msmtp
echo "set sendmail=/usr/bin/msmtp" | sudo tee -a /etc/mail.rc

# 6. Send test email
echo "How's it going?" | mail -s "Checking in" bob@aol.com

No comments:

Post a Comment