An MX record or Mail exchange record is a type of source record in the Domain Name System (DNS) specifying how Internet e-mail should be routed. MX records position to the servers to send an e-mail to, and which ones it should be sent to first, by right of way.
When an e-mail message is sent through the Internet, the sending mail transfer agent makes a DNS query requesting the MX record for the recipient's domain name, which is the section of the e-mail address following the "@". This uncertainty returns a list of host names of mail exchange servers accepting incoming mail for that domain, together with a preference number. The sending agent then attempts to launch an SMTP connection to one of these servers, opening with the one with the nominal first choice number, delivering the message to the first server with which a connection can be made. If no MX records were present, a second request is made for the A record of the domain as a substitute.
The MX system provides the capacity to run several mail servers for a single domain and the order in which they should be tried, growing the probability that mail may be delivered and providing the capacity to deal out the dealing out of inward bound mail across multiple physical servers.
The MX mechanism does not grant the ability to provide mail service on alternative ports, nor does it provide the ability to distribute mail delivery across a set of equal-priority mail servers by assigning a weighting value to each one. As of 2004, some MTAs, most notably exim, now support the use of SRV records for publishing the IP addresses, ports, priority, and weights of mail servers.
MX Priority:
A most important point of puzzlement is how the priority system works for MX selection. The relative priority of an MX server is strong-minded by the preference number present in the DNS MX record. When a remote client does an MX lookup for the domain name, it gets a list of servers and their first choice numbers. The MX record with the smallest first choice number has the highest precedence and is the first server to be tried. The remote client will go down the list of servers until it successfully delivers the message or gets permanently rejected due to an inaccessible server or if the mail account does not exist on that server. If there is more than one entry with the same preference number, all of those must be tried before moving on to lower-priority entries.
A preferred technique of spammers is to connect to the lowest priority MXs for a domain in an attempt to avoid any anti-spam filters that may be running on the primary MX. Computer viruses have also been known to employ this technique in an effort to avoid anti-viral software.