8.7. Delivering Administrative Notifications
A server that can only write its own journal is a server nobody hears
about. This section sends mail off the host: a Postfix satellite
configuration that hands every outbound message to a relay, authenticated
and TLS-verified, and wires systemd's failure hook to that path. The
examples use a relay named collector listening on port 2525 with
STARTTLS and authentication required - a stand-in for a provider's
smarthost, which uses the same settings on its own name and submission
port (commonly 587). Figure 8.5 shows the path.
Figure 8.5. Conceptual view of relayed mail. Everything entered with sendmail goes through the local queue to the relay over verified TLS with authentication; temporary failures defer and retry, permanent failures bounce back to the sender.
8.7.1. Sending Service and Job Notifications Through a Postfix Relay
On client1, as root, install Postfix - apt install postfix. The package
configuration asks two questions: the general type, where Satellite
system is the right answer (this host sends mail out but receives none),
and the system mail name, which becomes the domain in locally generated
addresses (client1 here). The relay settings are applied afterwards
with postconf -e, which writes parameters to /etc/postfix/main.cf:
# postconf -e 'relayhost = [collector]:2525' 'smtp_sasl_auth_enable = yes' 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd' 'smtp_sasl_security_options = noanonymous' 'smtp_sasl_tls_security_options = noanonymous' 'smtp_tls_security_level = verify' 'smtp_tls_CAfile = /etc/ssl/certs/handbook-ca.crt' 'smtp_tls_loglevel = 1' 'myhostname = client1' 'inet_interfaces = loopback-only'
One postconf invocation applying ten settings; Section 8.7.2 explains
each. The relay's certificate chains to the same lab CA built in
Section 8.6.2, so its certificate needs to be trusted here - copy it into
the system trust directory:
# install -m 644 /etc/rsyslog-tls/ca.crt /etc/ssl/certs/handbook-ca.crt
With a commercial smarthost the provider's CA chain takes this place. Start the service and validate the configuration:
# systemctl start postfix
# postfix check
Both silent - postfix check parses the configuration and ownership
rules and prints only on problems. The last piece before sending is the
credential map that smtp_sasl_password_maps names. The SASL map is a
plain text file that postmap compiles into a hash database:
# printf '[collector]:2525 relay:secret\n' > /etc/postfix/sasl_passwd
The redirection writes the file; nothing prints. The line's key must
match relayhost exactly, and its value is username:password. Restrict
both forms and compile:
# chmod 600 /etc/postfix/sasl_passwd
# postmap hash:/etc/postfix/sasl_passwd
# chmod 600 /etc/postfix/sasl_passwd.db
Then reload the daemon so the maps are picked up:
# systemctl reload postfix
All four commands are silent; Section 8.7.2 examines what they built.
Send the first message; the pipeline supplies the message text on
standard input, and sendmail -f sets the envelope sender:
# printf 'Subject: relay test\n\nfirst relayed message\n' | sendmail -f root@client1 alerts@example.net
The message is accepted into the queue; nothing prints. Check the queue and the delivery evidence:
# mailq
Mail queue is empty
# grep -E 'Verified TLS|status=sent' /var/log/mail.log | tail -3
2026-11-19T08:52:42.026463+00:00 client1 postfix/smtp[61545]: 4D24B20853: to=<alerts@example.net>, relay=collector[192.168.121.126]:2525, delay=16, delays=12/0/4/0, dsn=2.0.0, status=sent (250 2.0.0 Message accepted)
2026-11-19T09:08:32.852575+00:00 client1 postfix/smtp[67941]: Verified TLS connection established to collector[192.168.121.126]:2525: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
2026-11-19T09:08:33.660902+00:00 client1 postfix/smtp[67941]: 6C0492084F: to=<alerts@example.net>, relay=collector[192.168.121.126]:2525, delay=9.6, delays=3.8/1/4.7/0, dsn=2.0.0, status=sent (250 2.0.0 Message accepted)
Selected output; the first line is an identical delivery from an earlier
run of the same test, and the two 09:08 lines are this one. Read them in
order: the Verified TLS connection established line records the
negotiated protocol and cipher and that the certificate verification
succeeded; the status=sent line records the relay's 250 acceptance
with the queue ID (6C0492084F), the recipient, and the delays per
stage. The path works - now wire service failures to it. systemd's hook
is OnFailure= in the [Unit] section: units named there are started
when this one enters the failed state. The notification itself is two
small files. Contents of /usr/local/sbin/handbook-alert, the sender:
#!/bin/sh
unit="$1"
{
echo "To: alerts@example.net"
echo "Subject: [$(hostname)] $unit failed"
echo
systemctl status "$unit" --no-pager 2>&1 | head -20
} | /usr/sbin/sendmail -t
The script composes a message whose body is the failing unit's own
status output and hands it to sendmail -t, which reads the recipients
from the headers. Contents of
/etc/systemd/system/handbook-alert@.service, the template unit that
runs it:
[Unit]
Description=Send failure notification for %i
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/handbook-alert %i
The @ makes this a template: %i expands to the instance name, which
is the failing unit's name. Contents of the demonstration unit,
/etc/systemd/system/handbook-notify-demo.service:
[Unit]
Description=Handbook notification demonstration
OnFailure=handbook-alert@%p.service
[Service]
Type=oneshot
ExecStart=/bin/false
OnFailure=handbook-alert@%p.service says: when this unit fails, start
handbook-alert@ with this unit's name (%p) as the instance. Make
the script executable, load the units, and trigger the failure:
# chmod 755 /usr/local/sbin/handbook-alert
# systemctl daemon-reload
# systemctl start handbook-notify-demo.service
Job for handbook-notify-demo.service failed because the control process exited with error code.
See "systemctl status handbook-notify-demo.service" and "journalctl -xeu handbook-notify-demo.service" for details.
The demo unit failed exactly as designed. The interesting part is what started because of it:
# journalctl -u handbook-alert@handbook-notify-demo.service -n 5 --no-pager
Nov 19 09:10:31 client1 systemd[1]: Starting handbook-alert@handbook-notify-demo.service - Send failure notification for handbook-notify-demo...
Nov 19 09:10:31 client1 systemd[1]: handbook-alert@handbook-notify-demo.service: Deactivated successfully.
Nov 19 09:10:31 client1 systemd[1]: Finished handbook-alert@handbook-notify-demo.service - Send failure notification for handbook-notify-demo.
The alert unit ran, sent, and finished. And the mail went out through the same verified relay as before:
# mailq
Mail queue is empty
One mechanism, all failure mail: any unit that matters gets the same
OnFailure= line, and every failure lands in the alerts@example.net
mailbox with the status attached.
8.7.2. Authenticated Smarthosts, TLS Verification, and Protected Credentials
The ten settings applied in Section 8.7.1, in full:
| Setting | Purpose |
|---|---|
relayhost = [collector]:2525 |
Hand all outbound mail to this relay; the brackets suppress MX lookups |
inet_interfaces = loopback-only |
Listen only on loopback: this host receives no mail |
myhostname = client1 |
This host's own name in envelopes and headers |
smtp_sasl_auth_enable = yes |
Authenticate to the relay |
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd |
Where the credentials live |
smtp_sasl_security_options = noanonymous |
Refuse mechanisms that allow anonymity |
smtp_sasl_tls_security_options = noanonymous |
Same, over TLS |
smtp_tls_security_level = verify |
Require TLS with a verified certificate |
smtp_tls_CAfile = /etc/ssl/certs/handbook-ca.crt |
The trust anchor for that verification |
smtp_tls_loglevel = 1 |
Log one line per TLS session (the Verified line) |
Confirm the effective result - postconf -n prints only non-default
settings, and the pipeline trims it to the relevant parameters:
# postconf -n | grep -E "relayhost|smtp_sasl|smtp_tls_security|smtp_tls_CAfile|inet_interfaces|myhostname"
inet_interfaces = loopback-only
mydestination = $myhostname, client1, localhost.localdomain, , localhost
myhostname = client1
myorigin = $myhostname
relayhost = [collector]:2525
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/handbook-ca.crt
smtp_tls_security_level = verify
smtpd_banner = $myhostname ESMTP $mail_name (Debian)
The mydestination, myorigin, and smtpd_banner lines match the grep
pattern and were set when the package was configured; they are not part
of the relay changes. smtp_tls_security_level is worth its own table,
because it is the difference between "encrypted" and "verified":
| Level | Postfix requires... | Use |
|---|---|---|
none |
no TLS | nothing should |
may |
TLS if offered, certificate not checked | opportunistic privacy on arbitrary destinations |
encrypt |
TLS, certificate not checked | forced privacy, unknown provider |
verify |
TLS, chain verified against smtp_tls_CAfile |
a relay you have a trust anchor for |
verify is the only level that makes the connection trustworthy rather
than merely unreadable to bystanders; Section 8.7.3 shows what its failure
looks like. The credentials from Section 8.7.1 deserve their own
inspection. First, that the map actually answers for the relay's name,
with the password masked in this transcript:
# postmap -q '[collector]:2525' hash:/etc/postfix/sasl_passwd | sed 's/:.*/:REDACTED/'
relay:REDACTED
The pipeline queries the compiled map and rewrites everything after the first colon, so the credential is never echoed in full. And the protection:
# stat -c "%U:%G %a %n" /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
root:root 600 /etc/postfix/sasl_passwd
root:root 600 /etc/postfix/sasl_passwd.db
Both files are root-only. Two practical notes: after changing the text
file, rerun postmap - the daemon reads the compiled map, not the text -
and the smtp client consults the map at delivery time, so a rotation of
credentials needs no reload. Never put credentials in a unit file or an
Environment= line: environment values are visible in
systemctl show, which is exactly where secrets must not be.
8.7.3. Inspecting Queues, Retries, Delivery Failures, and Undeliverable Alerts
mailq lists the queue; postqueue -p prints the same listing; and the
failures are where the design earns its keep. First a verification
failure. On client1, as root, create a decoy CA, point the TLS setting at
it, and reload:
# openssl req -x509 -newkey rsa:2048 -nodes -keyout /tmp/handbook-bogus-mail.key -out /etc/ssl/certs/handbook-bogus-ca.crt -days 30 -subj "/CN=Wrong Mail CA"
......+...+..+..+......+..........+..+............+ (progress dots omitted)
# postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/handbook-bogus-ca.crt'
# systemctl reload postfix
Both the setting and the reload are silent. Send a message:
# printf 'Subject: tls failure test\n\nshould fail verification\n' | sendmail -f root@client1 alerts@example.net
Silently accepted into the queue - and then refused by the verification:
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
95EFC2084F 278 Thu Nov 19 09:08:48 root@client1
(Server certificate not verified)
alerts@example.net
-- 0 Kbytes in 1 Request.
The message sits in the queue with the reason in parentheses. The mail log names the exact failure:
# grep 'certificate verification failed' /var/log/mail.log | tail -2
2026-11-19T08:50:44.104796+00:00 client1 postfix/smtp[61307]: certificate verification failed for collector[192.168.121.126]:2525: untrusted issuer /CN=Handbook Lab CA
2026-11-19T09:08:52.850288+00:00 client1 postfix/smtp[68090]: certificate verification failed for collector[192.168.121.126]:2525: untrusted issuer /CN=Handbook Lab CA
The first line is from an earlier identical test; the 09:08:52 one is
this run. untrusted issuer /CN=Handbook Lab CA is precise: the relay's
certificate was fine, but the client no longer trusts who signed it -
exactly the verify level doing its job. Restore the correct CA, reload,
and flush the queue:
# postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/handbook-ca.crt'
# systemctl reload postfix
# postqueue -f
# mailq
Mail queue is empty
postqueue -f asks the queue manager to attempt every deferred message
immediately; the previously stuck message went out over the now-trusted
channel. Second failure mode: bad credentials. As root:
# printf '[collector]:2525 relay:wrongsecret\n' > /etc/postfix/sasl_passwd
# postmap hash:/etc/postfix/sasl_passwd
# chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
# printf 'Subject: auth failure test\n\nshould fail authentication\n' | sendmail -f root@client1 alerts@example.net
The first three commands rotate the map to a wrong password (the chmod
covers both files at once); the fourth silently queues the message:
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
CBA772084F 281 Thu Nov 19 09:09:17 root@client1
(SASL authentication failed; server collector[192.168.121.126] said: 535 5.7.8 Authentication credentials invalid)
alerts@example.net
-- 0 Kbytes in 1 Request.
# grep 'SASL authentication failed' /var/log/mail.log | tail -2
2026-11-19T08:51:11.864372+00:00 client1 postfix/smtp[61483]: 5ED472084D: to=<alerts@example.net>, relay=collector[192.168.121.126]:2525, delay=4.6, delays=0.3/0.02/4.2/0, dsn=4.7.8, status=deferred (SASL authentication failed; server collector[192.168.121.126] said: 535 5.7.8 Authentication credentials invalid)
2026-11-19T09:09:22.401216+00:00 client1 postfix/smtp[68265]: CBA772084F: to=<alerts@example.net>, relay=collector[192.168.121.126]:2525, delay=4.5, delays=0.41/0.02/4.1/0, dsn=4.7.8, status=deferred (SASL authentication failed; server collector[192.168.121.126] said: 535 5.7.8 Authentication credentials invalid)
Selected output; the first line is from the earlier identical test. Note
status=deferred with dsn=4.7.8: the rejection was temporary in
Postfix's eyes, so the message stays queued and will be retried at
growing intervals - wrong password or not. Fix the map and flush:
# printf '[collector]:2525 relay:secret\n' > /etc/postfix/sasl_passwd
# postmap hash:/etc/postfix/sasl_passwd
# chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
# postqueue -f
# mailq
Mail queue is empty
Third failure mode: the relay itself unreachable. In this lab the relay
is a service on collector that can simply be stopped (systemctl stop
handbook-smtpsink.service on collector, as root); a provider's smarthost
fails the same way from this side. Send a message with the relay down:
# printf 'Subject: outage test\n\nqueued while sink is down\n' | sendmail -f root@client1 alerts@example.net
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
60E902084F 274 Thu Nov 19 09:09:43 root@client1
(connect to collector[192.168.121.126]:2525: Connection refused)
alerts@example.net
-- 0 Kbytes in 1 Request.
The queue holds it with Connection refused. Start the relay again on
collector, then flush and confirm:
# postqueue -f
# mailq
Mail queue is empty
A permanent failure behaves differently: a 5xx rejection bounces
rather than retrying. The lab relay rejects one recipient domain on
purpose; send to it:
# printf 'Subject: bounce test\n\nshould be rejected\n' | sendmail -f root@client1 nobody@reject.invalid
The queue empties immediately - the message was refused outright:
# mailq
Mail queue is empty
The bounce came back to the envelope sender, root@client1, and was
delivered into root's local mailbox:
# grep -A3 'Diagnostic-Code' /var/mail/root | tail -6
Diagnostic-Code: smtp; 550 5.1.1 Recipient address rejected
--3B03020851.1795079420/client1
Content-Description: Undelivered Message
The bounce's Diagnostic-Code carries the relay's 550 5.1.1 answer.
Because the sender was root, the bounce is readable in /var/mail/root;
for units sending as other accounts it lands in that account's mailbox.
Bounces are why the envelope sender must be a monitored address.
The last case closes the loop that Section 8.7.1 opened: what happens to a failure notification when the relay is down. With the relay stopped again (same stop on collector), trigger the failing unit:
# systemctl start handbook-notify-demo.service
Job for handbook-notify-demo.service failed because the control process exited with error code.
See "systemctl status handbook-notify-demo.service" and "journalctl -xeu handbook-notify-demo.service" for details.
The alert unit ran and composed its mail - and the mail joined the queue like any other:
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
130BD2086E 1301 Thu Nov 19 09:10:50 root@client1
(connect to collector[192.168.121.126]:2525: Connection refused)
alerts@example.net
-- 1 Kbytes in 1 Request.
Start the relay, flush, and the notification goes out:
# postqueue -f
# mailq
Mail queue is empty
The lesson is structural, not incidental: an alert channel that shares the network and the relay with everything else is itself subject to outages, and a queue is a reasonable buffer for one - but a host whose only alert path is its own relay will queue silence during exactly the outages it should be reporting. A second path - a different relay, or a monitoring system that polls rather than waits to be notified - is the standard complement.