If you have the luxury of two computers connected to the internet using different IP-addresses you could use one of them as your backup mailserver. This backup server will receive email for the domains on your primary server when it is off-line or unreachable.

First install and configure your backup server just like you would a regular server. Install the following components as a minimum (it’s best just to install everything when possible):

  • MySQL, Apache and PHP
  • The basic mailserver (postfix & courier)
  • Postfixadmin

When you’ve done that make the changes listed here on your intended backup server.

First you need to create a file in the directory ‘/etc/postfix‘ called ‘mysql_relay_domains_maps.cf‘, which should contain:

user = postfix
password = postfixpassword
hosts = 127.0.0.1
dbname = postfix
query = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ’1′ AND active = ’1′

To make sure that mail does not get delivered to the backup server you need to change the file ‘mysql_virtual_domains_maps.cf‘ in the directory ‘/etc/postfix‘. Change the line:

query = SELECT domain FROM domain WHERE domain=’%s’

into:

query = SELECT domain FROM domain WHERE domain=’%s’ and backupmx = ’0′ and active = ’1′

Then add the line:

relay_domains = proxy:mysql:/etc/postfix/mysql_relay_domains_maps.cf

to the file ‘main.cf‘ in the ‘/etc/postfix‘ directory.

Then to activate the configuration restart postfix by using the command:

sudo postfix reload

Go to your Postfix admin website and configure the domains you want to use. Basically you will configure this identically to your primary server. The only difference here is that you check the backup MX checkbox.

Finally you’ll need to add a record to your DNS entries. Make sure the priority for the backup MX is lower than the primary server. Here is how I entered the information for DIYMacServer:

name                   priority  ip-address
mail.diymacserver.com     10     64.79.143.195
mail2.diymacserver.com    20     82.161.58.127