MX record
   HOME

TheInfoList



OR:

A mail exchanger record (MX record) specifies the
mail server Within the Internet email system, a message transfer agent (MTA), or mail transfer agent, or mail relay is software that transfers electronic mail messages from one computer to another using SMTP. The terms mail server, mail exchanger, and MX ho ...
responsible for accepting
email Electronic mail (email or e-mail) is a method of exchanging messages ("mail") between people using electronic devices. Email was thus conceived as the electronic ( digital) version of, or counterpart to, mail, at a time when "mail" mean ...
messages on behalf of a domain name. It is a
resource record The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned ...
in the
Domain Name System The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resources in the Internet or other Internet Protocol (IP) networks. It associates various information with domain names assigned t ...
(DNS). It is possible to configure several MX records, typically pointing to an array of mail servers for load balancing and redundancy.


Overview

Resource records are the basic information element of the Domain Name System (DNS). An MX record is one of these, and a domain may have one or more of these set up, as below:
Domain			TTL   Class    Type  Priority      Host
example.com.		1936	IN	MX	10         onemail.example.com.
example.com.		1936	IN	MX	10         twomail.example.com.
The characteristic payload information of an MX record is a preference value (above labelled "Priority"), and the domain name of a mailserver ("Host" above). The priority field identifies which mailserver should be preferred - in this case the values are both 10, so mail would be expected to flow evenly to both ''onemail.example.com'' and ''twomail.example.com'' - a common configuration. The host name must map directly to one or more address records (A, or AAAA) in the DNS, and must not point to any
CNAME record A Canonical Name record (abbreviated as CNAME record) is a type of resource record in the Domain Name System (DNS) that maps one domain name (an alias) to another (the canonical name). This can prove convenient when running multiple services (li ...
s. When an e-mail message is sent through the Internet, the sending
mail transfer agent The mail or post is a system for physically transporting postcards, letters, and parcels. A postal service can be private or public, though many governments place restrictions on private systems. Since the mid-19th century, national postal syst ...
(MTA) queries the Domain Name System for the MX records of each recipient's
domain name A domain name is a string that identifies a realm of administrative autonomy, authority or control within the Internet. Domain names are often used to identify services provided through the Internet, such as websites, email services and more. As ...
. This query returns a list of
host name In computer networking, a hostname (archaically nodename) is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web. Ho ...
s of mail exchange servers accepting incoming mail for that domain and their preferences. The sending agent then attempts to establish an SMTP connection, trying the host with the lowest "Priority" value first. The system allows
high-availability cluster High-availability clusters (also known as HA clusters, fail-over clusters) are groups of computers that support server applications that can be reliably utilized with a minimum amount of down-time. They operate by using high availability softwa ...
s of mail gateways to be built for one domain if necessary.HOWTO - Configure Round Robin and Load Balancing
Page modified: February 28 2014., zytrax.com
The MX mechanism does not grant the ability to provide mail service on alternative
port number In computer networking, a port is a number assigned to uniquely identify a connection endpoint and to direct data to a specific service. At the software level, within an operating system, a port is a logical construct that identifies a specific ...
s, nor does it provide the ability to distribute mail delivery across a set of unequal-priority mail servers by assigning a weighting value to each one.


MX preference, distance, and priority

According to RFC 5321, the lowest-numbered records are the most preferred.RFC 5321 This phrasing can be confusing, and so the ''preference number'' is sometimes referred to as the ''distance'': smaller distances are more preferable. An older RFC, RFC 974, indicates that when the preference numbers are the same for two servers, they have the same ''priority'', hence those two terms are used interchangeably.


The basics

In the simplest case, a domain may have just one mail server. For example, if an MTA looks up the MX records for example.com, and the DNS server replied with only mail.example.com with a preference number of 50, then the MTA will attempt delivery of the mail to the server listed. In this case, the number 50 could have been any integer permitted by the SMTP specification. When more than one server is returned for an MX query, the server with the smallest preference number must be tried first. If there is more than one MX record with the same preference number, all of those must be tried before moving on to lower-priority entries. An SMTP client ''must'' be able to try (and retry) each of the relevant addresses in the list in order, until a delivery attempt succeeds.RFC 5321


Load distribution

The standard approach to distributing a load of incoming mail over an array of servers is to return the same preference number for each server in the set. When determining which server of equal preference to send mail to, "the sender-SMTP MUST randomize them to spread the load across multiple mail exchangers for a specific organization", unless there is a clear reason to favor one.RFC 5321 An alternative approach is to use multihomed servers, where the one host returns several IP addresses. This method places the burden on the DNS rather than the SMTP-sender to perform the load balancing, which in this case will present a list of IP addresses in a specific order to the clients querying the A record of the mail exchanger. Since the RFC requires that the SMTP-sender use the order given in the A record query, the DNS server is free to carefully manipulate its balancing based on any method, including
round robin DNS Round-robin DNS is a technique of load distribution, load balancing, or fault-tolerance provisioning multiple, redundant Internet Protocol service hosts, e.g., Web server, FTP servers, by managing the Domain Name System's (DNS) responses to ad ...
, mail server load, or some undisclosed priority scheme.


"Backup" MX

Some domains will have several MX records, one of which is intended as a "backup" - with a higher preference number so that it would not normally be picked as the target for email delivery. However, in the case of errors from the lower-numbered hosts, (perhaps due to an outage of some sort), sending email servers will deliver to the "backup" host - ''queue.example.com'' in the example below:
Domain			TTL   Class    Type  Priority      Host
example.com.		1936	IN	MX	10         onemail.example.com.
example.com.		1936	IN	MX	10         twomail.example.com.
example.com.		1936	IN	MX	100        queue.example.com.
If the backup server has direct access to user mailboxes, mail will proceed there, but otherwise will likely be queued on ''queue.example.com'' until the outage is resolved. In the absence of this sort of arrangement, when a domain's mail servers are all offline, ''sending'' servers are required to queue messages destined for that domain to retry later. However, these sending servers have no way of being notified that a previously offline domain's servers are now available, and so resort to a polling schedule - and will only discover that the domain is available whenever they next attempt delivery. The delay between when a receiving domain's servers come online and when delayed messages are finally delivered can be therefore anywhere from minutes to days, depending on the retry schedule of the sending servers - and the receiving domain has no visibility or control over this.


Spammers

Spammer Spamming is the use of messaging systems to send multiple unsolicited messages (spam) to large numbers of recipients for the purpose of commercial advertising, for the purpose of non-commercial proselytizing, for any prohibited purpose (especial ...
s may deliberately direct mail to one of the backup (high distance) MX servers of a domain first, on the assumption that such a server will have less effective anti-spam filters. An anti-spam technique called nolisting is based on assuming this behaviour.


Handling of delivery failure

The SMTP RFC is ambiguous about exactly what kinds of delivery failure must result in re-attempting delivery via more distant MX records (those with higher preference values). When servers indicate temporary failures, either by explicitly sending a 4xx error or by ending the connection unexpectedly (which must be treated as a 451 error, according t
Section 3.8
of the RFC)
Section 4.5.4.1
says: However, when the sender retries, the RFC is silent about whether this should be to the same server, or a more "distant" MX record. It does say, i
Section 5.1
Some servers (such as
Sendmail Sendmail is a general purpose internetwork email routing facility that supports many kinds of mail-transfer and delivery methods, including the Simple Mail Transfer Protocol (SMTP) used for email transport over the Internet. A descendant of the ...
and Postfix 2.1 or later),''If the primary MX responds, but fails mid-transaction, Postfix 1.2 and 2.0 will not try a backup MX.''
, Re: does not change to mx with lower priority, From: Victor Duchovni (Victor.DuchovniMorganStanley.com) Date: Fri Nov 11 2005
will attempt the next-furthest MX server after some types of temporary delivery failures, such as greeting failures. Other servers (such as
qmail qmail is a mail transfer agent (MTA) that runs on Unix. It was written, starting December 1995, by Daniel J. Bernstein as a more secure replacement for the popular Sendmail program. Originally license-free software, qmail's source cod ...
and Postfix 2.0 or earlier) will only use more distant MX records if the servers specified in the shortest-distance MX records could not be contacted at all. Despite the difference, both behaviors are valid - since the RFC is not specific.


Fallback to the address record

In the absence of an MX record, email senders will attempt delivery to the address record - e.g. example.com. This is based on RFC 5321 sec. 5.1, which states : * SMTP clients must look up an MX record; * If (''and only if'') no MX record for the domain is present, treat the domain as if it had an MX record with the given domain as the target hostname and a preference value of 0 * Perform A or AAAA lookups as required to determine the IP address of the target hostname


Historical background

RFC 821 was published in 1982. It makes only passing references to DNS, because at the time the transition from HOSTS.TXT to the DNS had not yet started. RFC 883, the first description of the DNS, was published over a year later in late 1983. It described the experimental and little used MD and MF records. According to RFC 897 and RFC 921, the transition to DNS started in 1983, but HOSTS.TXT was not scheduled to be phased out until the end of 1985 and was not totally phased out until the late 1990s. In January 1986, RFC 973 and RFC 974 deprecated the MD and MF records, replaced them with MX, and defined the MX lookup with fallback to A. RFC 974 recommends that clients do a WKS lookup on each MX host to see if it actually supports SMTP and discard the MX entry if not. However, RFC 1123 changed this to say that WKS ''should not'' be checked. This means that SMTP had been in use for at least a year using HOSTS.TXT, and then another couple of years using A, MD, and MF, before MX came along. MD and MF were hard to use, so most people just used the A record. Under the circumstances, MX without fallback to A would not have worked because of the substantial installed base of mail servers using A records. The early use of MX was to identify gateways to other networks, but it did not come into wide use until the DNS was well established in the early 1990s.This section is adapted from
John Levine John R. Levine is an Internet author and consultant specializing in email infrastructure, spam filtering, and software patents. He chaired the Anti-Spam Research Group ( ASRG) of the Internet Research Task Force (IRTF), is president of CAUCE ...
br>ietf-smtp message


Standards documents

* (1987), ''Domain Names - Implementation and Specification'' * (1996), ''Common DNS Operational and Configuration Errors'' * (2008), ''Simple Mail Transfer Protocol'' * (2015), ''A "Null MX" No Service Resource Record for Domains That Accept No Mail'' Obsoletes: * (2001), ''Simple Mail Transfer Protocol'' (obsoleted by ''RFC-5321'') * (1986), ''Mail Routing and the Domain System'' (obsoleted by RFC-5321)


See also

*
SRV record A Service record (SRV record) is a specification of data in the Domain Name System defining the location, i.e., the hostname and port number, of servers for specified services. It is defined iRFC 2782 and its type code is 33. Some Internet protoco ...
*
Sender Policy Framework Sender Policy Framework (SPF) is an email authentication method designed to detect forging sender addresses during the delivery of the email. SPF alone, though, is limited to detecting a forged sender claim in the envelope of the email, which is ...
*
List of DNS record types This list of DNS record types is an overview of resource records (RRs) permissible in zone files of the Domain Name System The Domain Name System (DNS) is a hierarchical and distributed naming system for computers, services, and other resou ...
*
A record This list of DNS record types is an overview of resource records (RRs) permissible in zone file A Domain Name System (DNS) zone file is a text file that describes a DNS zone. A DNS zone is a subset, often a single domain, of the hierarchical ...
* Nolisting


References

{{DEFAULTSORT:Mx Record DNS record types Email