Postfix – Relay local mail to External Email Address

By | 2013/07/16

For good practice, one should receive root mail from your Linux server. Linux typically sends all sorts of important cron messages, alerts, logwatch emails, and other info to root@localhost.
I’ll show you how to use Postfix to relay this local mail to your own external email account such as a gmail account!

First, the VPS or server must have a valid PTR in DNS (reverse DNS) or email will be rejected by many systems including gmail. You can set this up from the hosting or VPS provider.
I would suggest making the PTR the hostname of your Linux server, though it can technically be most anything.

To check if a PTR record is in place, perform a host command against the IP address of your VPS:

$ host domain name pointer

1. Install postfix

(This example below uses Debian Wheezy)

$ sudo apt-get install postfix

When prompted, select: Internet Site

2. Edit /etc/aliases

Add line at bottom to send root mail to your email address.

$ sudo vim /etc/aliases
# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root

You can also add multiple destinations:

root: username,, 

It is somewhat common practice to send all root mail to a mailing list that admins subscribe to, as one example.

And finally run this to apply those changes and create aliases.db:

$ sudo newaliases