MX Records and MX Algorithm Part 2

MX algorithm is the logic behind MX records and email servers.

In part one I mentioned that MX record’s priority is used to avoid mail loops. In this post I will explain how it actually works.

So lets take a look at our example from previous part. MX records for domain:

We have 5 mail servers listed. Let’s sort them out by priority: MX preference = 5, mail exchanger = MX preference = 10, mail exchanger = MX preference = 20, mail exchanger = MX preference = 30, mail exchanger = MX preference = 40, mail exchanger =

When email server need to send email to domain it looks up the MX records for that specific domain and will try to deliver email to because it has the lowest priority (5).

Now imagine next situation is down and is not responding. In that case email is sent to server with next lower priority 10 ( in its turn looks up all of the MX records for the domain and  receives the same list of 5 MX records. It tries to deliver it again to server with lowest priority 5). Which  is down, as we know then it tries to send it to himself because he is next according to priority. After that a mail routing loop occur and server will try send email to itself indefinitely. Of course mail sending apps are smart enough to not send it forever and just drop it with the mail routing loop error code. 

To prevent this behavior email servers discard some MX records before deciding where to route email. First of all MX records are sorted by priority and checked for canonical domain name of itself. If local host is listed in MX records, mail server discards that MX record as well as records with the same priority value or higher. This helps do not send email messages to himself and to email servers which are further from the final destination.

Let’s get back to our example:

When email is received by it discards all the records with priority 10 and higher(In our case 20, 30, 40). Leaving only, which is down (as wee agreed at the beginning of our example).

Since server is not responding and all other MX records have been discarded mail server will defer delivery and queues email message. It will try to deliver email again after some time.

Thanks a lot for reading.

If you have any questions please leave them in a comment section below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.