As described in the previous post of this series DNS - Types of records, the record CNAME and MX define, respectively, that the name we are configuring and/or resolving is an alias (alternative name); and what email server should receive the email for the domain.
And everyone lives happily until someone uses a CNAME record incorrectly.
You see, the CNAME record means “everything you want to know about me,
pretend that my name is <this other name>
.
And this means that everything that is configured for that other domain applies as it was configured for this domain, and nothing that is configured for this domain applies.
And, obviously, the email server is also included. So, independently of the existence of a MX record in the current domain (the domain that have the CNAME), the email should be delivered to the MX server of the domain indicated by the CNAME record.
The problem is that not all email servers and email clients agree with this interpretation, so, depending on who is delivering the email - the email server of the sender or the software that is delivering it directly - the emails can be delivered to the server of the original domain or to the server of the domain pointed by the CNAME record.
How to avoid this problem?
If you want to receive the email in the original domain, and you want this email to be delivered to a email server that is different from the email server of the domain pointed by the CNAME record, then your option is to have the MX record in the original domain, and instead of the CNAME record use a A or AAAA record to point to the same IP as the destination domain.
If the email server is the same, then it does not matter, you should not have any problem, as the result is the same independently of the method used to find the mail server. All you need is the email server configured to receive email for both domains.
If you don’t want to receive email in the original domain, then you need the email server of the destination domain to be configured to reject emails for the original domain. Most mail servers’ default configurations reject email for domains they are not configured to receive, but it is always better to confirm than assume and having unexpected results.