CNAME vs MX DNS records: email service disabled

Did your email service stop working?

If you have a domain name (e.g. example.com) pointing to a web site, say a static web site at Amazon S3, or a blog at Blogger, etc., it might've been convenient to set up your domain's DNS records with a CNAME --- something like:
CNAME Record   ---   '@'   ---   mno3pqr4stu5.cloudfront.net
At least with NameCheap's Advanced DNS settings page, the '@' host name means a "naked domain" like "example.com".  So your readers can type in "http://example.com" and it'll go to your web site --- very convenient and friendly.

The problem with that is email to user@example.com won't work.

Here's why and how to fix it.

Why it doesn't work
If you have email set up for your own domain name, you might be using a service like Fastmail.com, or Google Apps for Work.  In any case, you'll need to set up some MX records for the naked domain "example.com", something like:
MX Record   ---   '@'   ---   ASPMX.L.GOOGLE.COM

But CNAME records override other records, like that MX record for email.  Actually, the standards say that if a CNAME record exist, no other DNS records should exist (c.f. Wikipedia).

I suppose the reason is that CNAME means Canonical Name, as in a given domain's actual, canonical name, is this other name.  So when the DNS query for "example.com" turns up a CNAME Record, it makes a new query to "mno3pqr4stu5.cloudfront.net" (for the example above) --- completely bypassing the MX Record above.

How to fix it
(1) Use a www subdomain for your web site, e.g.:
CNAME Record   ---   'www'   ---   mno3pqr4stu5.cloudfront.net
(2) Set the naked domain to forward to the www subdomain, e.g.:
URL Redirect   ---   '@'   ---  'http://www.example.com'
Most domain name services will let you set up a URL Redirect.  e.g. NameCheap calls it a "URL Redirect" record, with the option to make it "Unmasked", "Masked", or "Permanent (301)".

It's technically not a DNS record on its own, but an "A Record" pointing to the DNS company's own server.  When your reader's web browser accesses "http://example.com", the DNS company's server sends back a 301 or 302 redirect message to go to the target web address (i.e. http://www.example.com in the above URL Redirect record), or sends a web site accessing the target web address in an HTML frame.

I'm not sure but I suspect the "Unmasked URL Redirect" with NameCheap sends back a 302 redirect.

Varying DNS companies will have different terms for this, but the idea's the same.

A "frame" or "masked" redirect is probably not a good idea nowadays.  As for how to choose between 301 vs 302 redirect, see references below.

(3) Set up your mail server MX records on your naked domain as usual, e.g.:
MX Record   ---   '@'   ---   ASPMX.L.GOOGLE.COM
There's obviously a few more records needed for email services, but I refer you to your own email service provider for details on the other MX records, SPF and DKIM records, etc. that's needed.

[1] SEO advice: discussing 302 redirects
[2] 302 Redirect vs. 301 Redirect: Which is Better?
[3] Which record type option should I choose for the information I’m about to enter?
[4] Types of Domain Redirects - 301, 302 URL Redirects, URL Frame (and CNAME)

No comments: