Skip to content

System Mail

Linux servers report problems by sending an email to the root user. Cron job output, automatic update reports, disk health warnings (smartd) and RAID failures (mdadm) all arrive this way. On most servers, nobody ever reads that mailbox.

This guide hands each of those emails to Apprise, so they reach you on any of the 206 supported services instead.

  • A small mail server (Postfix) runs on your server and accepts mail for root.
  • Mail for root is passed on to a dedicated apprise user.
  • That user’s .forward file hands each message to apprise --email-input.
  • The email’s subject becomes the notification title. Its sender, date and text become the body.
  • Files in the email (attachments, images and forwarded emails) are sent along as attachments, to the services that accept them. Up to 50 are sent from each email. --email-attach-max changes that, and --email-attach-max=0 sends none.
  • If the notification can not be sent, the mail server keeps the email and tries again later, so nothing is lost while a service is down.

This guide assumes:

  • A single Linux server where you can use sudo
  • systemd is available
Terminal window
sudo apt install postfix python3-venv

When asked for the type of mail configuration, choose Local only. Postfix then only accepts mail sent from this server.

Install Apprise in its own folder, apart from the Python packages your distribution manages:

Terminal window
sudo python3 -m venv /opt/apprise
sudo /opt/apprise/bin/pip install apprise

The mail server will run it from /opt/apprise/bin/apprise. To update it later, run sudo /opt/apprise/bin/pip install --upgrade apprise.

Confirm your version supports email input:

Terminal window
/opt/apprise/bin/apprise --help | grep email-input
Terminal window
sudo useradd --system --create-home --home-dir /home/apprise \
--shell /usr/sbin/nologin apprise

The mail server runs the .forward command as this user. Your notification URLs (and the tokens inside them) stay readable by this user only, and nobody can log in as it.

Write your Apprise URLs, one per line, into the apprise user’s configuration file. Replace the example URL with your own:

Terminal window
sudo -u apprise mkdir -p -m 0700 /home/apprise/.config/apprise
sudo -u apprise tee /home/apprise/.config/apprise/apprise.conf >/dev/null <<'EOF'
# One Apprise URL per line
discord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_js
EOF
sudo -u apprise chmod 0600 /home/apprise/.config/apprise/apprise.conf

Send a test notification as the apprise user:

Terminal window
sudo -H -u apprise /opt/apprise/bin/apprise -vv -t "Test" -b "Apprise is ready"

First, create the .forward file that hands each message to Apprise:

Terminal window
echo '"|/opt/apprise/bin/apprise --email-input --exit-codes=sysexits"' \
| sudo -u apprise tee /home/apprise/.forward
sudo -u apprise chmod 0644 /home/apprise/.forward
  • --email-input reads the email the mail server passes in.
  • --exit-codes=sysexits tells the mail server whether to try again later. See Exit Codes.
  • The chmod matters: mail servers such as Exim ignore a .forward file that other users could change.

Then redirect root to the apprise user. Open the aliases file with sudo and add this line. If a root: line already exists, change it rather than adding a second one.

File: /etc/aliases

root: apprise

To also keep a copy in a local mailbox, list that user as well, for example root: chris, apprise.

Apply the change:

Terminal window
sudo newaliases
Terminal window
printf 'Subject: Hello from %s\n\nSystem mail now reaches Apprise.\n' \
"$(hostname)" | /usr/sbin/sendmail root

The notification should arrive within a few seconds. From now on, anything your server mails to root reaches you the same way.

Apprise tells the mail server what happened, and the mail server acts on it:

What Apprise did What the mail server does
Sent the notification (to at least one service) Nothing more. The email is done.
Could not send it anywhere Keeps the email and tries again later, for several days.
Found no service matching --tag Returns the email to its sender, since trying again can not help.
Could not read the email (for example, it is broken) Returns the email to its sender.

If a service refuses the email’s files (for example, one too big for it) and nothing could be sent, Apprise sends the text once more without them, and says so at the end of the notification. It does not when a service ran out of time, since that service may still deliver the first try.

To see emails waiting to be retried, and to retry them right away:

Terminal window
# List waiting emails
sudo mailq
# Retry them now (Postfix)
sudo postqueue -f
# Retry them now (Exim)
sudo exim4 -qff

Check what the mail server did with the last messages:

Terminal window
# Postfix
sudo journalctl -t postfix/local -n 20
# Exim (Debian)
sudo tail -n 20 /var/log/exim4/mainlog

Each Postfix line ends with status=sent, status=deferred or status=bounced, followed by anything Apprise printed.

  • “You must specify at least one service URL”: Apprise could not find or read its configuration. Make sure the file is in /home/apprise/.config/apprise/ and owned by apprise, then repeat the test from Add Your Notification Services.

  • Nothing mentions apprise at all: the alias is not active. Check the root: line and run sudo newaliases again.

  • “Permission denied” on Rocky Linux, AlmaLinux or Fedora: restore the SELinux labels with sudo restorecon -R /home/apprise.

  • To see each step Apprise takes, pipe a test email into it by hand. -vvv shows how the email was read (its body, each attachment and anything left out) and what was sent:

    Terminal window
    printf 'Subject: Test\n\nHello\n' \
    | sudo -H -u apprise /opt/apprise/bin/apprise --email-input -vvv
Questions or Feedback?

Documentation

Notice a typo or an error?

Technical Issues

Having trouble with the code? Open an issue on GitHub:

Made with love from Canada