Sending e-mails via mailbox.org with msmtp on Fedora

updated 2 min read #tutorial #networking #linux

This guide shows how to send system mail on Fedora through a mailbox.org account with msmtp, for example alerts from the ZFS event daemon.

I run several ZFS pools and want the ZFS event daemon, zed, to notify me of errors. So I created an alias at my e-mail provider, mailbox.org, and send these notifications to my private mailbox from that alias.

First, install msmtp, a very lightweight SMTP client, and s-nail, a mailx-compatible mail program that provides the mail command:

dnf install msmtp s-nail

Then copy msmtp’s example system configuration to /etc and adjust it:

cp /usr/share/doc/msmtp/msmtprc-system.example /etc/msmtprc
text /etc/msmtprc
account default

host smtp.mailbox.org
port 587

tls on
tls_starttls on

auth plain
user <[email protected]>
password <mailbox.org-password>

from [email protected]

allow_from_override off
set_from_header on

syslog LOG_MAIL

This is a system-wide SMTP account, and not every user should be able to read the password, so restrict the file’s permissions:

chmod 600 /etc/msmtprc

With these permissions, only root can send mail through this account, which is fine for zed.

To keep the password out of the configuration file altogether, msmtp can read it from a command with passwordeval instead of password, for example from a password manager or a key ring.

Finally, set msmtp as the MTA (Mail Transfer Agent) for s-nail:

text /etc/mail.rc
set mta=/usr/bin/msmtp

Now send a test mail. The command shouldn’t print anything:

echo 'Message body' | mail -s 'A subject' [email protected]

Result#

If the test mail arrives, every program that uses mail, such as zed, can now send notifications through the mailbox.org alias. Thanks to syslog LOG_MAIL, msmtp logs each delivery, so journalctl -t msmtp shows what happened if a mail doesn’t arrive.

Sources#

cd ~/writing