Well I did this some time ago, I still think writing things done may help if I encounter this again.
To move the mail server to another server, and lost mails as less as possible, here is my steps:
- Set your DNS server so your domains get a lower TTL. Do this as early as possible if you have a high TTL before.
- Setup mail server on the new server, use the same settings on the old server, and make sure everything works.
- Sync all the mails from the old server to new server. This takes a long time
- Sync again, this should take a shorter time
- Stop the old mail server
- Do a final Sync
- Start the new mail server
- Update your DNS so the mx record point to the new server
- Done. Check the status and make sure things are OK.
- This is for situations that we only have one mail server. If we already have a backup mail server, things will be different.
- We don’t use the priority of mx record here, cause we don’t want in-consistency between the two servers
- Most mail servers will retry for at least 24 hours if they can’t deliver a mail (either because we close down the old mail server or their DNS is not updated yet and can’t find the new server) so as long as TTL is small enough, we are good and no mail should be lost.