How do I move my website to a new server without interruption to email?
There are four functions you have to take care of with regards to email:
- People sending your users email.
- Your users collecting their email.
- Your users sending email.
- Your mail server passing those emails on to other people's servers.
Each one of these requires handling potentially a different DNS entry.
Your MX record. It should currently hold a name such as
mail.example.com
which in turn should hold an A record containing the IP address where other people can send your users email. If your MX record isexample.com
instead ofmail.example.com
you will probably want to change it prior to the migration.What your users put in their mail client as their POP or IMAP server. This can be a raw IP address or your main domain (
example.com
) or a subdomain. It's common to use something likepop.example.com
,imap.example.com
ormail.example.com
.What your users put in their mail client as their SMTP server. As with the POP and IMAP settings, this is often a subdomain such as
smtp.example.com
.The two DNS records that matter for this are your SPF record(s) and your PTR record. You will not want to change your SPF record apart from maybe adding the new web server in if it sends mail. Some mail servers expect your forward and reverse DNS to match, hence if the mail server IP address has a PTR pointing to
example.com
andexample.com
now resolves to the new web server IP address, some mail servers will reject email your users send to them.
What I would do in your situation:
- Create
mail.example.com
,pop.example.com
,imap.example.com
andsmtp.example.com
and give them all A records pointing at the mail server. - Verify that every user in your organisation is using some combination of those and only those subdomains in their mail clients. (Don't forget smart phones.)
- Verify that your MX records are using one of those subdomains.
- Verify that the PTR for your mail server's IP address is one of those subdomains.
- Make sure all these DNS changes have time to clear out of other people's caches. This means waiting as long as the longest existing TTL.
- Change the DNS for your domain to point to the new web server.
Notes:
- You can change the
www
subdomain fairly easily and safely without affecting email. (Unless you have done something weird like puttingwww.example.com
in your user's mail clients.) You could even stop here and not bother with any of the steps above. Leave a web server running on the mail server that does nothing but issue a 301 redirect towww.example.com
. - Doing all the changes above, while potentially slow and arduous now, will allow you to avoid much grief in the future because all of your independent services are now pointing to separate subdomains and all your users are using a consistent naming scheme to find those services. Future changes will be easy.
- You can test DNS changes out yourself by editing your own hosts file. This will allow you to check that your users can send and receive email and that other people can send you email.
Scenario: Email will continue going where it's currently going. Web site will move to a new server.
Change the A record for the web site (if you're using an A record for www), or for the web site host server (if you're using a CNAME for www) to point to the ip address of the new server.
No change to, nor discussion of, the MX record is required.
The MX DNS entry of your domain should be pointing on your old server after you moved the website. You then shouldn't have an interruption in service.
You must set mx record for your email to the old server and set up A record to a new one server for your website. Thats all. MX maps a domain name to a list of message transfer agents for that domain and record A returns a 32-bit IPv4 address, most commonly used to map hostnames to an IP address of the host.
All modification are safe and should not impact on any downtime of any service. You must ofcource first set up website on new server test it than make changes to dns. Ad MX record and change A record.