By default many GNU/Linux systems run their own local SMTP service on localhost
to send emails both locally and to the Internet. Nullmailer is a simple SMTP client to send email from a GNU/Linux system to a smarthost (MTA) that will handle the mail delivery. Using a smarthost means the system can send authenticated emails and satisfy modern DNS and email setups. Other options exist, such as MSMTP, or running an MTA like Exim or Postfix, but nullmailer
offers a most minimalist option.
This document will guide you through installing and configuring nullmailer
to send administrative email out of a system to the sysadmin group.
Pre-requisites
- The domain is configured in mx.z7l.eu and in DNS
- E.g.,
host -t mx domain.example
returnsdomain.example mail is handled by 10 mx.z7l.eu
- E.g.,
- The hostname in
/etc/hostname
is a FQDN (e.g.,host.domain.example
) - We’re using Debian stable (AKA bookworm at the time of this writing)
Installation
apt install nullmailer
Configuration
cd /etc/nullmailer
# Default destination
x=$(hostname -f); echo "sysadmin.${x//./-}@z7l.eu" > adminaddr
# Default sender (an alias to proc@)
echo "toor@$(hostname -d)" > allmailfrom
# Default domain to append to username
echo $(hostname -d) > defaultdomain
# SMTP credentials (get $PASS from mx.z7l.eu)
install -m 0400 -o mail -g mail /dev/null remotes
echo "mx.z7l.eu smtp --port=465 --ssl --user=proc@$(hostname -d) --pass=$PASS" > remotes
systemctl restart nullmailer
Test
The test email should be simple (single To:
address, no Cc:
) otherwise it will create errors that won’t be easy to track.
cat > ~/test.email <<EOD
Subject: Nullmailer test
From: some.email@domain.example
To: you@ps.zoethics.org
Hop !
EOD
cat ~/test.email | nullmailer-inject boom
journalctl -feu nullmailer
Since allmailfrom
was set, the From:
address will be overridden. Be sure to replace you@ps.zoethics.org
by an email address you can read!
Conclusion
Software on your system will now be able to send notifications to a central email address.
Caveat
This solution is good for systems with no users except sysadmins, since any user with sudo
privilege will be able to read the SMTP credentials. But then, systems with untrusted users who can run sudo
should probably not send email directly.