A customer moves their mail to Microsoft 365. The MX record at Cloudflare now points to <tenant>.mail.protection.outlook.com. The customer migrates mailboxes, Outlook clients reconfigure. A week later, a few messages are still landing in the cPanel server’s /home/user/mail/ directory — old senders cached an old MX, hit the cPanel host’s IP, and cPanel accepted the message because the domain is still in its local mail list. The fix isn’t only the MX; cPanel needs to know mail is no longer its problem.
What’s happening
cPanel decides whether to accept mail for a domain based on three places, not the MX record:
/etc/localdomains— domains cPanel delivers locally./etc/remotedomains— domains cPanel routes via MX (and refuses local delivery)./var/cpanel/cpanel.configand the WHM Email Routing Configuration — the “Local Mail Exchanger / Remote Mail Exchanger / Backup / Automatic” mode.
When you update the MX in DNS but leave the domain in localdomains and the mode set to “Local Mail Exchanger”, cPanel still accepts SMTP for the domain (because its server name is in the SMTP connection target) and delivers to local mailboxes. The new mail provider sees most of the mail, but the long tail of old senders, transactional services with hardcoded MX, and clients caching old DNS still hit cPanel.
The right setup for a domain moved to a third-party provider:
- MX records point to the new provider.
- Domain is in
/etc/remotedomains, not/etc/localdomains. - WHM Email Routing for the domain is set to “Remote Mail Exchanger”.
- cPanel mailboxes for the domain are removed (or at least disabled).
How to verify
Check what cPanel thinks:
grep example.com /etc/localdomains /etc/remotedomains
whmapi1 get_domain_info domain=example.com | grep -i mail_routing
Trace where Exim would deliver:
exim -bt test@example.com
If the output says it would deliver locally, cPanel is still accepting mail. If it says it would route to <external MX>, cPanel is correctly forwarding.
Watch live mail flow:
tail -f /var/log/exim_mainlog | grep example.com
If you see accepted and delivered for the domain, mail is being received locally despite the MX change.
What to do
- Confirm the MX is fully cut over.
dig +short MX example.com @1.1.1.1and@8.8.8.8should both show the new provider. - Switch the email routing in WHM to “Remote Mail Exchanger”. WHM > Service Configuration > Email Routing Configuration. Set the domain to Remote. This moves the domain from
/etc/localdomainsto/etc/remotedomainsand updates Exim’s configuration. - Confirm the move:
grep example.com /etc/remotedomains
! grep example.com /etc/localdomains
- Decide on existing cPanel mailboxes. The customer’s mail history before the migration lives in
/home/user/mail/. Options:- Leave the mailboxes in place but don’t deliver to them. Old messages stay accessible via cPanel webmail.
- Export to mbox/Maildir and hand over to the customer or import to the new provider.
- Disable the mailboxes (WHM > Mail Accounts) but keep the data on disk for a retention period.
- Set autoresponders or forwarders at the cPanel level if needed. For a few weeks during the cutover, you can configure cPanel to forward mail that does arrive to the new provider — but this is a stopgap, not a long-term setup. The MX is the authoritative pointer.
- Watch the Exim log for a week. Any mail still being accepted is a sign that something didn’t get the message:
tail -1000 /var/log/exim_mainlog | grep -E "accept.*example.com" | wc -l
- Remove the domain from cPanel mail handling entirely after a month if no traffic returns. WHM > MX Entry > Remote.
A common related issue: the customer also wants webmail for the old mail to remain accessible. Keep the mailbox data on disk and the user accounts active, but the routing set to Remote — that way nothing new gets delivered locally but the historical archive is still browseable via cPanel’s webmail interface.
Stack Harbor coordinates mail handoffs to third-party providers as part of migration solutions.