Skip to content

Mail flow continuity during a server migration

Keeping inbound and outbound mail flowing through a hosting cutover, without dropping messages, losing IMAP state, or breaking authentication.

Web cutovers are forgiving — a visitor who hits the old IP during DNS propagation just sees the old site for a minute. Mail cutovers are not. A message delivered to the old server during the propagation window sits in a mailbox the user is no longer reading. A message held by a sender’s queue because both MX records are answering inconsistently can sit for four hours and arrive after the user has emailed the sender to ask if anything is wrong. Mail continuity is a design problem, not a cutover-night problem.

What’s happening

Mail flow has three independent paths to keep alive across a migration. Inbound delivery follows MX records, which are TTL-cached at every sending mail server in the world for up to the MX record’s TTL. Outbound delivery uses the source server’s IP, which still has the reputation history but will stop being authorised in SPF as soon as the record is updated. Authentication (SPF, DKIM, DMARC) must remain valid at both source and destination simultaneously during the cross-over. And IMAP state — read flags, folder structure, sent items — lives on the source until it is replicated. None of these align automatically; each is its own move.

How to verify

Map mail before scheduling cutover:

dig +short MX example.com
dig +short MX example.com @1.1.1.1
exim -bp | wc -l
ls -la /home/<user>/mail/example.com/<account>/cur | wc -l
dig +short TXT example.com | grep -i spf

Count mailboxes, total mail size on disk, and queue depth. Identify whether the destination will run the same mail stack (Exim on cPanel, Dovecot IMAP) or a different one — moving Exim-to-Exim preserves Maildir layout; moving to anything else requires an IMAP-level sync with imapsync or equivalent. Confirm SPF will be updated to authorise both source and destination IPs during the crossover window.

The fix

Reduce MX TTL to 300 seconds 48 hours before cutover. The day of cutover, sync mailboxes with imapsync or rsync the Maildir if both ends are Dovecot — run an initial sync 24 hours ahead, then a final incremental during the maintenance window. Update SPF to authorise both source and destination IPs simultaneously; keep DKIM keys published on both servers (the public TXT record on each can coexist if selectors differ). Flip MX records and watch the source’s Exim queue with exim -bpc — when it hits zero and stays there for 30 minutes, the propagation is effectively complete. Leave the source receiving mail for at least 72 hours after the MX change as a safety net for slow resolvers, and forward anything that lands to the destination via /etc/valiases/example.com.

This is the cutover sequence we use for every mail-bearing migration in Migration — request a mail continuity plan.