Archive for the ‘Howto’ Category

Re-injecting emails collected on a different host (like a MX backup) into Postfix

Saturday, January 23rd, 2010

Due to recent hosting troubles I had to quickly deploy a backup MX for my primary mail server. This was quickly achieved using a VPS hosted by the Swedish webhost GleSys.

But since my customers needed to be able to read and reply to emails while the primary site was down, I couldn’t just let the backup system keep the incoming email in the queue and deliver them once the primary sit was up. I decided to deliver the emails locally but also keep a copy of all emails that passed through the system.

These archived emails were to be re-delivered once the primary site was up again, and here’s how I did it, step by step.

  • Set up a VPS for the backup MX host.
  • Set up the system using the same guide I used for the primary site, which was the great ISPmail tutorial by Christoph Haas.
  • Added the option always_bcc to the Postfix config, pointing it to a new local mailbox.
  • Once the primary server was up again, I set up getmail like this:
    • [retriever]
      type = SimplePOP3Retriever
      server = hostname_of_backup_mx
      username = username_of_backup_account
      password = secret
      [destination]
      type = MDA_external
      arguments = ("-i", "-bm", "-t")
      [options]
      verbose = 2

Running getmailrc quickly restored all the emails on the primary host. Remember not to run it multiple times since the default is to re-download already processed messages.

The downsides of this setup:

  • Deleted emails (like spam) are seen again by the users. POP users will receive duplicates of already retrieved messages. IMAP users will however have a mailbox which includes both old messages and the ones delivered to the backup server.
  • The spam filter wasn’t used in delivery process. I realize this could be achieved with fetchmail (which includes the SMTP delivery option that getmail lacks) but I decided to use getmail anyway.

I realize there might be prettier solutions to the original problem (BOTH delivering emails locally and keeping them in a queue for a primary MX), but I couldn’t find out how and this proved to be a pretty solid solution. Feel free to suggest better ways to solve the problem!