The zones that never have mail incidents on Cloudflare share one layout: a single DNS-only mail.example.com A record that carries the MX target and every client protocol, a proxied apex and www for the web, and — if users want browser mail — a separate orange-clouded webmail.example.com for the HTTP interface. The split means the proxy can do its job on web traffic while nothing on the mail path ever depends on a proxied name. Set it up once and the “someone toggled a cloud and mail died” class of incident stops being possible.
What’s happening
Cloudflare’s proxy carries HTTP and HTTPS; SMTP, IMAP, and POP3 pass through only as DNS answers, never as traffic. Any hostname doing double duty — an apex that is both the website and the MX target, a www that someone also typed into Outlook — is a standing conflict: the web side wants the orange cloud, the mail side breaks under it. A dedicated mail hostname dissolves the conflict by giving each protocol family its own name with its own proxy status.
The one real cost is visibility: a grey-clouded A record publishes the IP it points at. If mail and web share a server, the mail record reveals the web origin, and an attacker can aim traffic straight at it, past the WAF. That is not a reason to proxy the mail record — that just breaks mail — it is a reason to know the trade-off and, where it matters, split mail onto its own IP or host. Webmail is the other subtlety: Roundcube or cPanel webmail is an HTTP app, so it can sit behind the proxy and benefit from it — but only under a hostname used exclusively for the browser, never the one IMAP clients connect to.
What to check first
- What the MX currently targets. Apex,
www, or a proper mail name?dig +short MX example.com. - What users have in their mail clients. If half the office connects to
example.comfor IMAP, the migration includes their settings, not just DNS. - What certificate the mail server presents. A grey-clouded hostname talks straight to the origin, so the origin’s certificate must cover
mail.example.com— Cloudflare’s edge certificates never apply to DNS-only names. - Whether mail and web share an IP. Decides how much the origin-exposure trade-off matters to you.
How to verify
# The layout as the world sees it
dig +short MX example.com
dig +short A mail.example.com
dig @1.1.1.1 +short A mail.example.com
dig +short A webmail.example.com # Cloudflare IPs here are correct
# Mail protocols answer on the grey name with a valid certificate
openssl s_client -connect mail.example.com:25 -starttls smtp -brief
openssl s_client -connect mail.example.com:993 -brief
openssl s_client -connect mail.example.com:587 -starttls smtp -brief
The -brief output includes the verified certificate subject — it should name mail.example.com, not the server’s default hostname. Then a delivery check and the log:
swaks --to user@example.com --server mail.example.com
tail -f /var/log/exim_mainlog # or /var/log/maillog
The fix
-
Create the mail record, DNS-only:
mail.example.com A 203.0.113.25 (grey cloud)An A record, not a CNAME to the proxied apex — a CNAME inherits the apex’s proxied answers, which is the failure this layout exists to prevent.
-
Point the MX at it:
example.com MX 10 mail.example.com -
Standardize client settings on
mail.example.comfor IMAP (993), POP3 (995), and submission (587 or 465). One hostname on every device, matching the certificate. -
Put a certificate for
mail.example.comon the origin. Let’s Encrypt via HTTP validation works fine on a grey name; cPanel’s AutoSSL handles it automatically once DNS resolves to the box. -
Give webmail its own proxied hostname —
webmail.example.com, orange cloud, HTTPS only. Users who type it get the WAF and caching; IMAP clients never touch it. -
Sweep for leftovers: old
smtp./imap./pop.names should either be grey A records to the same IP or CNAMEs tomail.example.com(which stay DNS-only because their target is), so stragglers keep working during the settings migration.
When this fix is wrong
If mail lives at Microsoft 365, Google Workspace, or another hosted provider, you have no mail server to name — the MX points at the provider and this layout does not apply. If the driving concern is hiding the origin IP entirely while self-hosting mail, no DNS layout achieves that: the MX chain must end at a real, reachable IP. The options are a separate mail IP, a relay host in front, or hosted mail — the DNS-only vs proxied concept article walks through what the proxy can and cannot conceal.
Common mistakes
- Creating
mailas a CNAME to the apex and inheriting the proxy. - Proxying
mail.example.comafter a security scan flagged “exposed IP” — the scanner is describing how mail works, not a defect. - Forgetting the origin certificate, so clients connect and then throw name-mismatch warnings.
- Using the webmail hostname in IMAP settings because “it worked in the browser”.
- Leaving the MX pointed at the apex after building the new record, so the layout exists but nothing uses it.
Prevention
Write the convention into your zone standards: mail protocols get mail.*, always grey; web gets the apex and www, proxied at will; webmail is its own orange name. Audit proxy status after every zone import, and treat the Cloudflare dashboard’s MX warnings as blockers. The DNS record cookbook has the per-type proxy rules, and Cloudflare’s DNS documentation is the upstream reference.
Mail that breaks after a DNS move is one of the most common incidents we untangle — Stack Harbor manages the full DNS and mail path under Managed Cloud Ops; book an infrastructure review before the next migration.