You may be familiar with the local mail spool on your Linux system. Often error messages from failed cron jobs are
sent there. However this isn’t much use if the server goes down or loses network connectivity. It would be nice to have
it send those emails out to an external email inbox instead. That way you can be notified when disks fail in a RAID
array or when applications/services fail or produce errors.

We’ll be setting up email forwarding for the root mail spool. Most ISPs block SMTP port 25 for anti-spam and other
reasons so we’ll need an SMTP server we can authenticate to. You can have two choices here:

Obtain the SMTP server and port from your ISP and use your account’s credentials.

Use a dedicated Google Apps/G Suite/Gmail account.

This guide will use the Gmail route since I plan on using it for my home Fedora server and for my
cellular Raspberry Pi. Using non-ISP credentials allows you to use the same SMTP
account on different WiFi networks as well. However these instructions should work for ISP and any other SMTP provider.

Tip

I highly recommend using a dedicated email account for this. It’s not a good idea to put your main email credentials
in plain-text in any file even if it’s protected by file permissions. If a system gets remotely or physically
compromised you don’t want someone having access to your main email account.

The steps outlined in this guide have been tested on the following operating systems but should work for basically any
Linux distro:

First we must install software to forward mail and handle authenticating to the external SMTP server. There are several
MTAs (message transfer agents) available but I’ll be using Postfix. Let’s install it:

Note

On Debian the postfix install script will prompt you for some info. Select InternetSite as the general type of
configuration and use either gmail.com or your G Suite domain name for the system mail name.

Now that we’ve got Postfix successfully sending out email we need to configure the system to forward all of root’s mail
to your email address. Things like failed root cronjobs and other system-related mails will be forwarded to you.

First update /etc/aliases with the following at the bottom:

root:RECIPIENT@gmail.com

Then run newaliases to apply changes and run the mail command to test.