03 August 2019

What is an MX Record?

Mail Exchange, or MX records, are DNS (Domain Name System) records with the specialised function of delivering emails into respective addresses.

In simplified terms, an MX record tells users which machines are responsible for receiving incoming mail for domains and where emails sent to the domains should be directed to. Most customers host their mails with various service providers, and all necessary mail-related DNS records are developed automatically after the addresses have been added to the domain in the panel.

Users may choose to swap a domain’s mail service between their provider, Gmail/Google Apps or a different platform entirely.

Example of an MX record

MX records have two parts;

  • The priority
  • The domain name

For instance, 0 mail. SAMPLE.com

In the case given above:

  • The priority is ‘0’
  • The value of the number is inversely proportional to the priority. This means, the lower the number, the higher the priority.
  • The ‘mail.SAMPLE.com is its connecting mail server.
  • Outgoing email servers are linked to the MX server according to their priority.
  • Where two servers have an identical order of priority, one is picked randomly.

Who controls the MX records?

Each MX record is controlled at the organisation where the name servers are directed. For example, if a domain uses name servers owned by a particular host, then all changes to the DNS (even personalised MX records) can be made in the host’s panel.

If a person wishes to use a particular host’s mail service with a domain on a different name server, they can set up custom mail DNS records at the different DNS provider by using the mail DNS info from their current panel.

How does an MX record work?

Resource records are the fundamental information element of the DNS. They are recognised a specific identification (MX, A, NS and so on) and a DNS class such as CHAOS or the internet. Each record has a separate period of validity assigned to them. This indicates when the information they contain must be revived from an authoritative name server.

Resource records are arranged within the DNS according to their name field which is an FQDN (fully qualified domain name) of a node in the DNS tree. For an MX record, this indicates the domain name of the receiver’s email address. In other words, the characters that come after the @ sign that mark out the recipient’s account name.

The typical payload information of an MX record is the FQDN of a preference value and mail host. It is important that the host maps directly to one or few address records (A or AAA) in the domain name system, and must not be linked to any CNAME records.

When an email is forwarded via the internet, the sending MTA (Mail Transfer Agent) queries the DNS on MX records the recipients’ domain names. The query presents a full list containing host names for email exchange servers which accept inbound mails for respective domains and their preferences. The sender agents then try to set up a simple mail transfer protocol (SMTP connection).

MX distance, preference and priority

In Mail Exchange, the records with the lowest numbers are usually the most preferred. The phrase sounds ambiguous, so the preference number is often known as the distance. To state clearly, smaller distances are most preferred. RFC 974, which is an older RFC, shows that when the preference numbers for two servers are identical, their priority is the same. In such a scenario, both terms can be used interchangeably.

The fundamentals

A domain can have a single server. For instance, if an MTA checks the records of Mail Exchange for sample.com and the DNS server responded with just mail.sample.com and a preference number of 50, then the MTA will try to deliver the mail to the listed server. In this situation, the integer 50 could have been any number allowed by the simple mail transfer protocol.

Where multiple servers are returned for an MX query, each record’s preference number determines the relative priority of the server listed. When a client on another mail server (remote client) does an MX checkup for the domain name, it retrieves a server list and their respective preference numbers.

As stated, the least preference number is the one with the highest priority, and server(s) with low preference numbers are to be tried before other higher servers. In order to deliver a reliable mail service, the SMTP clients will continue to attempt delivery to relevant addresses on the list (by priority) until it achieves success. Where there are two or more MX records with an identical preference number, they must all be tried before attempting entries with lower proprieties.

The backup MX

A server that knows how to deliver to a relevant user’s email address (a target server) is usually most preferred. Servers with a lower priority or backup MX, usually store messages in a queue until a primary serve is available. If both servers are connected to each other in some way, the backup MX will queue a message temporarily before sending it to the primary MX.

> Learning Hub