How to setup a qmail server to be a backup server for another mail server.

by Chad C D Clark < chad.website AT superfrink DOT net >

Created 2004-03-31
$Id$

  1. Add the MX records for the domain. For example consider superfrink.net.
    1. Typically my DNS had one MX resource line that looked like:
        @ IN MX 10 mail.superfrink.net.
      This says all mail for the zone goes to the machine mail.superfrink.net(A bit beyond this file's scope, see chapter 4 in the O'Reilly DNS and Bind book.)
    2. Add a new entry for the backup mail server. Now my DNS has two MX records:
        @ IN MX 10 mail.superfrink.net.
        @ IN MX 20 hostingmail.webcorelabs.com.
      It is important that the backup server has a higher number (20 vs 10 in the example). The actual numbers are not important. The important thing is the main mail server (where the actuall mailboxes are) has the lowest number and any backup servers have a higher number. These numbers are the "distance" the mail servers are from the actual mailboxes. (Also see chapter 5 of the O'Reilly book.)
  2. Setup qmail on the spare backup machine.
    On my backup machine (hostingmail.webcorelabs.com) the qmail control/rcpthosts is updated frequently and used for the server's main domains. ie domains that it keeps the mailboxes for itself.

    I don't want to use control/rcpthosts for domains that the server is just a backup for. So we use control/morercpthosts which is ment for domains that are not a main focus for the server. Setup is as follows:
    1. Simply add your domain to control/morercpthosts on a line without anything else (create the morercpthosts file if it does not exist). So now the control/morercpthosts file has a single line in it:
        superfrink.net
    2. Next we have to tell qmail about the changes we made to the morercpthosts file. (Note: at this point you can read a few man pages: qmail-control , qmail-smtpd , qmail-newmrh ) To do this just run the simple command " qmail-newmrh ".

      You don't have to restart qmail or anything. It should just accept mail for the new domain now (eg, superfrink.net). And because the distance is larger the backup server should not be sent mail except when the real mail server (with the lowest distance) is unavailable.


Now the backup mail server will accept mail for superfrink.net and will keep it for a while and try to pass it on to the main mail server for delivery. If the backup server gives up (say after a week of trying to deliver the message) the sender of the email (ie the From: line) should be sent a bounce message explaining what happened.