The MX record directs emails to a mail server which allows email to be exchanged, received and sent.
What is a DNS MX record?
An MX (Mail Exchange) record directs email messages sent to email accounts within a domain (email addresses) to a mail server. The MX record specifies how emails should be routed according to the Simple Mail Transfer Protocol (SMTP, the standard protocol for routing all emails). An MX record must always point to a different domain or subdomain.
It is a field consisting of a number and a hostname which allows you to define with a priority the preferred server which will receive emails sent on a domain (0 being the highest priority, with the highest preference).
It is possible to create multiple MX records (primary, secondary, etc.) to define multiple mail servers on the same domain, in case of unavailability or failure for example, but this is not recommended, and is even discouraged UNLESS you have all the necessary human resources to configure and maintain them correctly.
Furthermore, it should be noted that since the email service is asynchronous and not instantaneous, in the event of unavailability or shutdown of your mail server, other mail servers (or MTAs) that attempt to send it mail during this period will simply wait and try again later (most of the time, for five days, the maximum duration configured by default in sendmail and Postfix).
Therefore, there is no risk of losing mail if your domain's mail server is down or unreachable for a few days.
Learn more: http://www.bortzmeyer.org/mx-secondaire.html
Using multiple MX records with different priorities
Example of an MX record:
| example.com | recording type | priority | value | TTL |
|---|---|---|---|---|
| @ | MX | 0 | mailhost1.example.com | 33200 |
| @ | MX | 10 | mailhost2.example.com | 33200 |
The "priority" values indicate the preferred server for email delivery; the lowest "priority" value is the one preferred and therefore takes precedence. Emails will always go to mailhost1 first, since 0 is less than 10. If a message fails to be delivered to mailhost1 , it will then be redirected to mailhost2 .
Using multiple MX records with equivalent priorities
It is also possible to configure 2 MX records with the same priority so that the mail servers receive the same amount of mail:
| example.com | recording type | priority | value | TTL |
|---|---|---|---|---|
| @ | MX | 10 | mailhost1.example.com | 33200 |
| @ | MX | 10 | mailhost2.example.com | 33200 |
This configuration allows for load balancing between the two mail servers.
Note: "Null MX" - For a domain that never receives mail and has no active email, it is possible to use "null MX", which consists of putting a dot ( . ) on the right side of the MX record, as the server name, with a priority of 0. This is a defensive measure.
domain.com. 33200 IN MX 0 .
The "Null MX" (or "Null MX") officially means "No Service MX", the rejection will be immediate and the user, notified right away, will be able to correct their mistake.
RFC 7505 : A “Null MX” No Service Resource Record for Domains that Accept No May
Learn more: https://www.bortzmeyer.org/7505.html
Can MX records point to a CNAME?
No, that's not possible. MX records must point directly to a server's A or AAAA record. Pointing to a CNAME is prohibited by the RFC documents that define how MX records work .
Learn more about CNAME records and their uses.
What is the DNS process for querying an MX record?
The Mail Transfer Agent (MTA ) software is responsible for querying a domain's MX records. When an email address sends an email, the MTA sends a DNS query to identify the recipient's mail server(s). The MTA establishes an SMTP connection with this/these mail server(s), starting with the highest priority servers (in the first example above, mailhost1.example.com ).
What is a backup MX record?
A backup MX record (secondary, tertiary, quaternary, etc.) is simply a non-priority MX record, meaning it's defined with a higher "priority" value (meaning a lower priority order). Under normal operating conditions, mail will be routed to the priority servers (those with the lowest priority level). In the first example above, mailhost2.example.com is the backup server because email traffic will be routed to mailhost1.example.com as a priority while it's operational. If mailhost1.example.com fails or becomes unavailable , mail will then be routed to mailhost2.example.com as a fallback.