People send billions of emails daily, but most don’t know about the underlying infrastructure powering this massive information exchange. For example, how does your mail server know which computer will receive a message for a particular addressee? The answer is stored in the DNS database, and is known as a Mail Exchange (MX) record.
This article will dive deep into MX records and explain all you need to know about it. We’ll learn how they work, why they’re essential, and how to ensure your MX records are correct.
What Are MX Records?
A mail exchange (MX) record specifies the server that accepts email messages for a specific domain. It is a record added to the Domain Name System (DNS) configurations for a particular domain.
There are usually multiple servers within a domain, including mail servers, web servers, File Transfer Protocol (FTP) servers, etc. Each one fulfills a specific purpose and doesn’t handle the tasks of other servers. For example, a mail server accepts and relays email messages, and an FTP server only hosts files.
When someone sends an email to an address attached to your domain, their email server will need to know the right host to pass the message to. Hence, it looks up your domain’s MX records via the DNS system to find the host name of the mail server for your domain.
Having no MX records means having no guide to direct incoming emails to the correct server where they'll be processed. The email system may attempt to deliver the message using the domain's A record (which points to the IP address of the server hosting the domain) as a fallback. However, this is not a reliable method for email delivery.
In summary, MX records allow emails to flow reliably across the internet.
How Do DNS MX Records Work?
Before understanding MX records, you should know the role of Message Transfer Agents (MTAs) and DNS servers in delivering emails. When anyone types an email and hits the send button, the MTA is the software that transfers the email from the sender’s mail server to the recipient’s via the Simple Mail Transfer Protocol (SMTP).
Let’s say [email protected] is sending a message to [email protected]. Technically, John is transferring data from his email server to Jane’s mail server. When John sends a message, his MTA is instructed to transfer the message content to Jane’s server. On its own, the MTA doesn’t know the correct address of Jane’s mail server, so it queries the DNS system for the MX records tied to Jane’s domain, unione.io.
After querying the DNS system, the MTA knows the correct address of the server receiving emails on behalf of UniOne.io. It then forwards the message there to be processed and delivered to Jane. If UniOne.io had no MX records, the MTA wouldn’t know where to send John’s message, and it would fail to deliver.
Here’s an example of DNS MX records for unione.io:
Why two records? The reason is that you may have more than one mail server for your domain. This may be necessary if you shut down one of your servers for maintenance but do not want to lose any important emails. The Value is the mail server's hostname, and Priority indicates the preference for each server. The lower the number, the higher the priority.
When an MTA queries the DNS system for the MX records attached to unione.io, it’ll see these two mail server addresses:
The MTA will first try mailhost1.unione.io because 10 is lower than 20. If that fails, it’ll try to send the message to mailhost2.unione.io. If both servers have the same priority figures, the MTA will choose one at random.
The last line, TTL (Time to Live), specifies the duration (in seconds) before subsequent changes to the MX records take effect. In this example, any change to the MX record will take effect no sooner than 300 seconds (5 minutes).
How Do You Add DNS MX Records?
Virtually all domain registrars allow you to control your DNS records. You can add or remove MX records to your domain whenever you want. The steps will differ according to your registrar, but they all follow a similar pattern:
- Log into your domain registrar.
- Choose the domain to which you want to add MX records.
- Click Advanced, Advanced DNS, DNS Settings, DNS Configurations, or something similar.
- Click the button to add a new record.
- Choose “MX record” and fill in the correct details. Note that any mail host name you enter must directly correspond to an A or AAAA type record for that hostname. Otherwise, it would be impossible to determine an IP address for that host.
- Save your changes.
How Do You Check Your MX Records?
DNS records are publicly available, which makes them easy to query. You can use designated MX query tools like MxToolbox.com, NsLookup.io, and the Google Admin Toolbox. Just type your domain name in the search bar, and these tools will retrieve all the MX records attached to it.
These tools allow you to verify that your DNS MX records are specified correctly. You can also use it to confirm if any change to your MX records has taken effect.
Common Problems With MX Records
Watch out for these common mistakes when creating MX records:
- Missing records: If any part of your record is missing or invalid, it may be discarded.
- Misspelled records: MX records are sensitive, and spelling mistakes in host name will prevent emails from being delivered.
- Incorrect priority values: If your DNS MX record has inconsistent priority values, email delivery may become unreliable because of inefficient load balancing between the mail servers.
Now you know the basic things about DNS MX records. We explained how they work, why they’re essential, and how to add MX records to your domain. We also explained how to check your domain’s MX records and the common mistakes to avoid when adding them.