
Email moves rarely fail because of SMTP. They fail because DNS changed in the wrong place, the MX target didn’t resolve, or caches kept sending mail to yesterday’s server. This MX record setup tutorial walks through a cautious cutover: audit what’s live, change only what you intend, verify propagation, and confirm messages land on the new system.
Use the same flow whether you’re moving to a VPS (Postfix/Exim), switching providers (Google Workspace/Microsoft 365), or splitting web hosting from mail hosting. The goal is simple: keep inbound mail delivering before, during, and after the DNS change.
What you’re changing (and what you must not guess)
MX records tell other mail systems which hostnames accept email for your domain. They do not point directly to IP addresses.
Each MX target must resolve to an address using A (IPv4) and/or AAAA (IPv6) records.
- MX hostname: the mail exchanger (example:
mail.example.com). - Priority: lower number wins (10 beats 20). Use multiple MX records for failover.
- TTL: how long resolvers cache the record. Short TTL before cutover reduces “wait time”.
If you host mail yourself, MX is only the routing layer. Plan for PTR/rDNS, SPF, DKIM, and DMARC as well.
You can have perfect MX and still get hammered by spam filtering if authentication is missing.
Prerequisites checklist (10 minutes that prevent 2 hours of rollback)
- Access to your DNS zone (registrar DNS, cPanel DNS, Cloudflare, etc.).
- The new mail provider’s required MX values (hostnames + priorities).
- For self-hosted mail: a working mail service listening on port 25 and a hostname you control.
- A way to test from a terminal:
digandopenssl(Linux/macOS) or WSL on Windows.
If you’re building DNS on cPanel infrastructure with redundant nameservers, set that up first.
HostMyCode has a dedicated guide for that: cPanel DNS Cluster setup tutorial.
Step 1: Audit your current MX and mail-related DNS
Start by capturing the current state. You’ll want it for rollback.
This snapshot can also reveal stale provider records, parked-domain templates, or a default mail. setup you didn’t expect.
# Check current MX
DIG_DOMAIN="example.com"
dig +noall +answer MX ${DIG_DOMAIN}
# Check the hostnames your MX points to
# (replace with each MX target you find)
dig +noall +answer A mail.example.com
dig +noall +answer AAAA mail.example.com
# Useful context: SPF, DKIM (common selectors), and DMARC
# SPF is a TXT at the root
dig +noall +answer TXT ${DIG_DOMAIN}
# DMARC is at _dmarc.example.com
dig +noall +answer TXT _dmarc.${DIG_DOMAIN}
Red flag: your MX points to a hostname that doesn’t resolve. Many senders will bounce immediately. Others will queue briefly, then bounce later.
Red flag: you see an MX like 0 . (a “null MX”). That intentionally rejects inbound email for the domain. Remove it only if you’re certain you want to receive mail.
Step 2: Lower TTL ahead of the cutover (optional, but strongly recommended)
If your MX TTL is high (for example 1 hour or 4 hours), lower it the day before you switch. A TTL of 300 seconds is a practical value for planned cutovers.
- Change MX TTL (and the
A/AAAAfor the MX hostnames) to 300. - Wait for the old TTL to expire before you do the real cutover.
This won’t eliminate mixed delivery. It does shorten the window where senders keep using cached records.
Step 3: Decide your target MX design (single, failover, or provider set)
Pick a pattern and stick to it. Most problems show up when people improvise mid-change.
Option A: Provider-defined MX set (most common)
Google Workspace, Microsoft 365, Zoho, and many transactional providers require multiple MX records with specific priorities. Use their values exactly.
Don’t collapse them into “one MX” because it looks cleaner.
Option B: Your own mail host + backup MX (self-hosted)
You can publish two MX records pointing at two servers. The secondary host must actually accept mail for the domain and queue/relay it correctly.
A “backup MX” that isn’t configured for proper relay/queue behavior often creates silent loss or backscatter.
Option C: Single MX (acceptable for small setups, higher risk)
One MX record is fine if your server is stable and you trust its queueing behavior.
For business mail, redundancy tends to pay for itself the first time there’s an outage.
Step 4: Create/verify the mail hostnames (A/AAAA records)
MX points to a hostname, not an IP. That hostname must resolve.
For a VPS mail host, mail.example.com is the typical choice.
# Example DNS records (conceptual)
mail.example.com. 300 IN A 203.0.113.10
mail.example.com. 300 IN AAAA 2001:db8::10
example.com. 300 IN MX 10 mail.example.com.
IPv6 note: only publish an AAAA record if your mail stack is listening on IPv6 and your firewall permits it.
“Sort of” enabling IPv6 is a reliable way to get intermittent delivery failures that are painful to trace.
If you need a stable hosting base for mail + websites, a HostMyCode VPS gives you full DNS and service control without shared-hosting constraints.
Step 5: Update MX records in your DNS provider (cutover time)
Make the change deliberately. If your DNS UI is easy to misclick, don’t “edit in place.”
Remove the old MX set and add the new set cleanly. That keeps the active state unambiguous.
- Remove old MX records you no longer want active.
- Add the new MX record(s) with the correct priorities.
- Confirm there is no leftover “parking” MX from a registrar template.
Common mistake: mixing providers. Example: leaving an old MX pointing to cPanel while adding Microsoft 365 MX.
Depending on caching and sender behavior, inbound mail can split between systems.
Step 6: Validate MX from multiple resolvers (don’t trust your laptop DNS)
Check what the world sees, not just what your local network resolver returns.
If you use Cloudflare or another DNS proxy/CDN, remember MX isn’t proxied. The zone still has to be correct.
# Check using your default resolver
DIG_DOMAIN="example.com"
dig +short MX ${DIG_DOMAIN}
# Check via Cloudflare's resolver
dig @1.1.1.1 +short MX ${DIG_DOMAIN}
# Check via Google's resolver
dig @8.8.8.8 +short MX ${DIG_DOMAIN}
Then confirm the MX target resolves:
MX_TARGET="mail.example.com"
dig @1.1.1.1 +short A ${MX_TARGET}
dig @1.1.1.1 +short AAAA ${MX_TARGET}
If DNS looks correct but some senders still deliver to the old system, you’re usually waiting on caches. That’s expected.
Lowering TTL ahead of time reduces how long this lasts.
For planned moves (web + mail + SSL), it helps to run a proper DNS cutover plan. Keep this guide bookmarked: DNS cutover tutorial for safe migrations.
Step 7: Confirm the destination mail server accepts inbound mail
Even with correct MX, mail can still bounce. Common causes include port 25 blocks, a broken SMTP banner, or a hostname/certificate mismatch.
Test SMTP connectivity to the new destination.
# Basic SMTP reachability test (connect)
# Replace mail.example.com with your MX target
nc -vz mail.example.com 25
# Start an SMTP session (you should see a banner)
openssl s_client -starttls smtp -connect mail.example.com:25 -servername mail.example.com
What “good” looks like: a 220 banner appears, then STARTTLS completes with a certificate chain you expect.
If you self-host, sanity-check your server hostname and HELO/EHLO identity as well. HostMyCode covers that in: email server hostname setup tutorial.
Step 8: Reduce mail loss during the switch (practical routing tactics)
There will be a transition window. Your goal is to make it uneventful.
- Keep the old mailbox service running for at least 48–72 hours after MX cutover. Some senders retry slowly.
- Don’t delete old mailboxes immediately. Cached MX can still hit the old system, and you need those messages accepted.
- Use a temporary catch-all carefully. It can save a misaddressed message, but it also attracts spam.
- Watch queues and bounces on the new system. Fix failures quickly, then ask senders to retry if needed.
If you’re moving between cPanel servers, sync-based migration is usually cleaner than a “big bang” swap.
See the companion guide: cPanel Transfer Tool tutorial for safe account moves.
Step 9: Update SPF/DKIM/DMARC to match the new sender (so replies don’t go to spam)
MX handles inbound routing. SPF/DKIM/DMARC determine whether your outbound mail is trusted.
After a provider change, update these records. If you don’t, you’ll often fail alignment and land in junk.
- SPF (TXT at root): authorize the new sender’s IPs/services.
- DKIM (TXT at selector._domainkey): publish the provider’s DKIM public key.
- DMARC (TXT at _dmarc): set a policy and receive reports.
If you want a full, methodical flow for deliverability and testing, pair this tutorial with: Email deliverability setup guide. It’s the difference between “mail sends” and “mail reliably lands in the inbox.”
Step 10: Troubleshooting quick hits (what to check when mail doesn’t arrive)
When someone reports “email is down,” put it in one bucket: DNS, connectivity, or message acceptance. Then test that layer directly.
Problem A: MX still shows the old provider
- Confirm you edited the correct DNS zone (registrar DNS vs. Cloudflare vs. cPanel).
- Check for multiple authoritative nameservers with different zone data.
- Verify propagation with
dig @1.1.1.1anddig @8.8.8.8.
Problem B: MX points to a hostname that doesn’t resolve
- Add or fix the
A/AAAArecord for the MX target. - Remove IPv6 (
AAAA) temporarily if your mail server can’t accept IPv6 traffic.
Problem C: Server accepts connections but rejects recipients
- Confirm the domain exists on the mail server (virtual domain/hosted domain).
- Check for anti-spam policy blocking test sources.
- Read logs while reproducing the issue.
If you run your own mail stack on a VPS, logs are the fastest source of truth.
For Postfix/Exim queue issues, this companion piece helps you diagnose without making deliverability worse: VPS mail queue troubleshooting tutorial.
Step 11: Safe rollback plan (you should write this down before you change anything)
Rolling back an MX change is usually straightforward: restore the previous MX set and wait for caches to age out.
The part people miss is documenting what “previous” actually was.
- Export or screenshot your DNS zone before changes.
- Keep old MX values in a text file with priorities and TTL.
- Keep the old mail service running until you’re confident in the new route.
- If you lowered TTL earlier, rollback will also be faster.
Example: Clean MX cutover to a self-hosted mail server on a VPS
Here’s a concrete, minimal example for example.com hosted on your own VPS IP 203.0.113.10.
- Create
mail.example.comas anArecord to your VPS IP. - Set
example.comMX tomail.example.comwith priority 10. - Confirm port 25 reachable and STARTTLS works.
- Update SPF to include your server’s sending identity.
- Add DKIM and DMARC once outbound mail is verified.
# Verify end state
# 1) MX should point to mail.example.com
dig +short MX example.com
# 2) mail.example.com should resolve
dig +short A mail.example.com
# 3) SMTP banner should appear
nc -vz mail.example.com 25
If you want less day-to-day admin overhead, consider managed VPS hosting for your mail-and-web stack. It’s a better fit when you don’t want to spend your evening reading postfix logs.
If you’re moving email and websites to your own server, start with infrastructure you can rely on. A HostMyCode VPS gives you predictable resources and the DNS control you need for clean MX changes.
For production mail workloads where uptime and response time matter, managed VPS hosting helps you keep deliverability and security steady, without winging it.
FAQ: MX record changes that trip people up
How long do MX changes take to work?
Most resolvers follow your TTL. If TTL is 300, you’ll often see changes within minutes. Some caches and senders can still lag, so plan for 24–72 hours of overlap.
Can I point an MX record directly to an IP address?
No. MX records must point to a hostname. That hostname then resolves to an IP via A/AAAA.
Should I keep my old MX as a backup during migration?
Only if you intend to accept mail there and forward/sync it. Mixed-provider MX sets commonly cause split delivery and missing messages.
Do I need to change anything else besides MX?
For inbound mail routing, MX may be enough. For outbound deliverability, update SPF/DKIM/DMARC to match the new sending system.
Summary: the boring path is the reliable path
Good MX cutovers aren’t clever. They’re careful: audit first, lower TTL ahead of time, publish MX with resolving hostnames, verify from multiple resolvers, and keep the old system alive long enough for stragglers to arrive.
If you want a stable home for mail routing, DNS, and migrations in 2026, start with a HostMyCode VPS and treat DNS like production infrastructure, because that’s exactly what it is.