Reading system mail with neomutt(1)

This post takes a look at how to read "system mail" with the neomutt(1) program on FreeBSD. For those unfamiliar, the periodic(8) utility is run regularly via /etc/crontab and its output is sent as mail to root. By default the scripts executed via periodic(8) perform system tasks such as running security checks, among others (see /etc/periodic/* for a complete list)

My preferred email client happens to be neomutt(1) but as a rule of thumb I try to avoid running programs outside the FreeBSD base system as root. That led me down the path of configuring a separate (unprivileged) user account for reading "system mail", and in this post I will share how my setup eventually took shape.

useradd

The first step is to create a new user account whose primary responsibility will be reading "system mail" with the neomutt(1) program:

##
# FreeBSD: add user
root@localhost# pw useradd \
  -n sysmail \
  -d /home/sysmail \
  -M 700 \
  -s /bin/sh \
  -m \
  -c "Reads system mail"

alias

The second step is to create a mail alias that forwards mail sent to root onto our new user account. This can be done by editing the /etc/mail/aliases file, and there should already be plenty of aliases defined in this file.

At the very end of the file, add a new alias, and afterwards run newaliases to rebuild the alias database. Once that is done, the new alias should take effect:

##
# FreeBSD: add mail alias
root@localhost# echo "root: sysmail" >> /etc/mail/aliases
root@localhost# newaliases

neomutt

When it comes to the third step we now have everything in place to read system mail as the sysmail user. Quite often I keep neomutt running in a tmux session that I attach and detach from throughout the day but whether or not you do the same is left up to you.

Also keep in mind that after you create the sysmail user account it is unlikely to have any mail. This can be fixed by running periodic daily manually (as root) or waiting for the next time periodic runs via cron. After you're sure there is mail to read, neomutt is ready to go:

##
# FreeBSD: read system mail
sysmail@localhost$ neomutt -f /var/mail/sysmail

Conclusion

In conclusion I hope this post was helpful. In closing I'd like to suggest a few links for further reading. They explore this topic with a bit more depth and I highly recommend taking a look if that's what you're after: