Let's say I want to start a service where customers get their own subdomain on my domain for email addresses only.
I have an A record for mydomain.com and a CNAME for www.mydomain.com
If I add a wildcard MX record for *.mydomain.com, my understanding is that any email coming to my domain will route to the associated mailserver, except for www because CNAME's cannot overlap with MX records.
So email addresses such as
- foo@mydomain.com
- foo@customer1.mydomain.com
- foo@bar.customer1.mydomain.com
- foo@customer2.mydomain.com
Should all work correctly.
- foo@www.mydomain.com
Will NOT work correctly.
Then, in my SMTP mailserver, I can parse the domain out of the email address, and route the message appropriately. Is there anything wrong with this plan?
Best Answer
It's not completely clear what your overall plan entails but here are some clarifications about how wildcard records work in general. I think this should clarify what may potentially be a problem.
Wildcard records do not cover the base name (ie `*.example.com.` does not cover `example.com.`).
Wildcard records never overlap with anything, whether `CNAME` or any other record types.
From the [wildcard section of RFC1034](https://www.rfc-editor.org/rfc/rfc1034#section-4.3.3): > Wildcard RRs **do not apply**: > > ... > > - **When the query name or a name between the wildcard domain and > the query name is know to exist.** For example, if a wildcard > RR has an owner name of "*.X", and the zone also contains RRs > attached to B.X, the wildcards would apply to queries for name > Z.X (presuming there is no explicit information for Z.X), but > not to B.X, A.B.X, or X.
(emphasis added)
Other than the above, which may or may not be a problem for what you had in mind, are you sure you actually want any random names that people out on the Internet come up with to have `MX` records (eg `.example.com` and whatnot)?