How to Move a qmail Installation

Blog Topics:

I was running a mail server (SMTP and POP3) for the domain on the host and needed to move it to Here's how to do this:

  1. Have your users use the address for accessing their POP3 mailboxes, or create a address for this purpose (this needs to be done weeks in advance!)

  2. Set the DNS TTL down to 15 minutes to allow a speedy transition. (If you're also moving the DNS, move it now and give the changes time to spread!)

  3. Recreate the email account structure on through Plesk, and cut and paste the hashed passwords from/to users/poppasswd. This seems sufficient for retrieving messages through POP3. To update users/cdb, you can run /var/qmail/bin/qmail-newu, but I don't know whether this is necessary.

    If you also need SMTP authorization and/or Plesk Control Panel access, then you'll have to fix the MySQL database as well. Look at the psa.mail table to get the account_id, and you'll find the encoded password in the psa.accounts table.

  4. Reconfigure qmail on to start forwarding email to
    • Set control/smtproutes as
    • Remove from control/locals and control/virtualdomains, but keep it in control/rcpthosts
    • Restart qmail to get this to take effect

    From this point on, all email for is automatically relayed to someone's inbox at

  5. Be sure to test this; you may need to restart some daemon — I've simply restarted the server.

  6. If you want, you can tell your users to retrieve their email one last time from the old server. Change DNS of (and from to — this will take some time to become effective, but no messages will get lost; they'll either go to and be relayed to, or they'll go directly to

  7. Process the remaining messages for each user under mailnames as follows:
    • Copy the attachments from @attachments, be sure to retain/restore ownership and access modes.
    • Copy the old unread emails in Maildir/new to a new Maildir/x directory, fix ownership and access modes (so they are the same as a newly arrived message on, which is not necessarily what they were on old!), and only then move them to the new Maildir/new directory.
      (BTW, emails on the old have file names like, and emails arriving on have names like, I don't whether this makes any difference...)
    • Copy any stored emails in Maildir/cur and fix these up, too.

This procedure should allow you to migrate a qmail MTA from one host to another without causing any problems for your users, even if they continue to retrieve their email as usual.

You'll find that some MTA's will continue to send email to long after the DNS change should be completed, so if you can, keep the MTA on running and forwarding for a few days or weeks. However, if you use qpsmtpd on to reject spam, then you should either whitelist the old or shut it down, because would probably bounce undeliverable spam to innocent third parties, which is a BAD THING.