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.
How It Works
Section titled “How It Works”- A small mail server (Postfix) runs on your server and accepts mail for
root. - Mail for
rootis passed on to a dedicatedappriseuser. - That user’s
.forwardfile hands each message toapprise --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-maxchanges that, and--email-attach-max=0sends 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
Install a Mail Server
Section titled “Install a Mail Server”sudo apt install postfix python3-venvWhen asked for the type of mail configuration, choose Local only. Postfix then only accepts mail sent from this server.
sudo dnf install postfix python3sudo systemctl enable --now postfixPostfix only accepts mail sent from this server by default.
sudo zypper install postfix python3sudo postconf -e inet_interfaces=loopback-onlysudo systemctl enable --now postfixThe postconf line makes Postfix accept mail sent from this server only. By default it listens on every network interface.
sudo pacman -S postfix pythonsudo postconf -e inet_interfaces=loopback-onlysudo newaliasessudo systemctl enable --now postfixThe postconf line makes Postfix accept mail sent from this server only. By default it listens on every network interface.
Install Apprise
Section titled “Install Apprise”Install Apprise in its own folder, apart from the Python packages your distribution manages:
sudo python3 -m venv /opt/apprisesudo /opt/apprise/bin/pip install appriseThe 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:
/opt/apprise/bin/apprise --help | grep email-inputCreate the Apprise User
Section titled “Create the Apprise User”sudo useradd --system --create-home --home-dir /home/apprise \ --shell /usr/sbin/nologin appriseThe 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.
Add Your Notification Services
Section titled “Add Your Notification Services”Write your Apprise URLs, one per line, into the apprise user’s configuration file. Replace the example URL with your own:
sudo -u apprise mkdir -p -m 0700 /home/apprise/.config/apprisesudo -u apprise tee /home/apprise/.config/apprise/apprise.conf >/dev/null <<'EOF'# One Apprise URL per linediscord://4174216298/JHMHI8qBe7bk2ZwO5U711o3dV_jsEOFsudo -u apprise chmod 0600 /home/apprise/.config/apprise/apprise.confSend a test notification as the apprise user:
sudo -H -u apprise /opt/apprise/bin/apprise -vv -t "Test" -b "Apprise is ready"Send Root’s Mail to Apprise
Section titled “Send Root’s Mail to Apprise”First, create the .forward file that hands each message to Apprise:
echo '"|/opt/apprise/bin/apprise --email-input --exit-codes=sysexits"' \ | sudo -u apprise tee /home/apprise/.forwardsudo -u apprise chmod 0644 /home/apprise/.forward--email-inputreads the email the mail server passes in.--exit-codes=sysexitstells the mail server whether to try again later. See Exit Codes.- The
chmodmatters: mail servers such as Exim ignore a.forwardfile 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
File: /etc/aliases
File: /etc/aliases
File: /etc/postfix/aliases
root: appriseTo also keep a copy in a local mailbox, list that user as well, for example root: chris, apprise.
Apply the change:
sudo newaliasesTest It
Section titled “Test It”printf 'Subject: Hello from %s\n\nSystem mail now reaches Apprise.\n' \ "$(hostname)" | /usr/sbin/sendmail rootThe notification should arrive within a few seconds. From now on, anything your server mails to root reaches you the same way.
When a Service Is Down
Section titled “When a Service Is Down”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:
# List waiting emailssudo mailq
# Retry them now (Postfix)sudo postqueue -f
# Retry them now (Exim)sudo exim4 -qffTroubleshooting
Section titled “Troubleshooting”Check what the mail server did with the last messages:
# Postfixsudo journalctl -t postfix/local -n 20
# Exim (Debian)sudo tail -n 20 /var/log/exim4/mainlogEach 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 byapprise, then repeat the test from Add Your Notification Services. -
Nothing mentions
appriseat all: the alias is not active. Check theroot:line and runsudo newaliasesagain. -
“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.
-vvvshows 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
Security Notes
Section titled “Security Notes”Questions or Feedback?
Technical Issues
Having trouble with the code? Open an issue on GitHub: