MX Records and MX Algorithm Part 1

MX records (mail exchanger records) are special DNS records used for email communication. Sending server looks up the MX records for the recipient domain and establishes SMTP session with that server to deliver email message.

A little bit of History

Originally function of MX record has been split between two record types: MD (Mail Destination) and MF (Mail Forwarder). MD was pointing to the main email server which was responsible for receiving email for the given domain. MF in its turn was pointing to the backup server where emails will be redirected when main server is not responding and which will forward email later on to the final destination.

Early experience showed that function separation didn’t work well and was very overwhelming for admins running email service. Mailer needed both records MD and  MF attached to the domain name in order to decide where to send email. DNS lookup of one type or another would make name server cache record of that only type. So every mailer had to do 2 queries one for MD and one for MF or do not accept cached records at all.

Later on two records have been integrated into single record type called MX. This solved a lot of  problems. Now mailer just needed MX record for the specific domain name to make a decision where to route email.

MX Record basics

MX record consist of name of the mail server which is responsible for either receiving or forwarding email to the next hop and a special parameter called priority. Which  is an unsigned 16 bit integer (between 0and 65535) which indicates the mail exchanger’s priority. It has been implemented to avoid mail loops. The priority value itself is not important and  is taken to consideration only if other MX records for the specific domain exists.

Keep in mind that there are no rule for which priority value to use or not to use. It is completely up to you or your email admin. Only requirement is that you understand  what priory does and make one server more preferable for email delivery then the other.

You can also have records with the same priority which will do a load balancing for your incoming emails.

Note It will not be  true load balancing as mailers will decide which server to use if there are few with same priority often there is no logic in decision making process just simple random.

Email servers should attempt an email delivery to the server listed in MX records with the lowest priority first. If delivery fails to it then mail servers should attempt to deliver to less preferable(higher priority) server. Basically lower priority means try me first and then go to the the guys with the higher one. If mailer successfully deliver email to the host with the lowest priority it will not try to deliver it again to hosts with higher priority.

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.

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