RFC 974

Mail routing and the domain system

๐Ÿ“… published January 1986, from ietf

Status of this Memo โœจ

Okay bestie, let's start with the title block ๐ŸŽ€. This is RFC 974, titled MAIL ROUTING AND THE DOMAIN SYSTEM. It was written by Craig Partridge of CSNET CIC BBN Laboratories Inc and dated January 1986 ๐ŸŒธ. The header doesn't list any obsoletes or updates, so nothing gets replaced there ๐Ÿ’….

The memo describes how mail systems on the Internet are expected to route messages using the domain system from RFCs 882, 883 and 973 ๐Ÿ’Œ. Distribution of this memo is unlimited ๐Ÿฆ‹.


Introduction ๐Ÿงš

So the whole point of this memo is to explain how mailers decide where to send a message addressed to a given Internet domain name ๐Ÿ“ฌ. This involves talking about how mailers read MX RRs, which are the records used for message routing ๐Ÿ’œ. Heads up though: this memo says nothing about how mailers handle MB and MG RRs, which are used for interpreting mailbox names ๐Ÿ™ˆ.

Under RFC-882 and RFC-883, some of the old assumptions about mail addresses changed ๐Ÿ˜ญ. Before that, you could usually assume that if a message was addressed to a mailbox at something like LOKI.BBN.COM, you could just open an SMTP connection to LOKI.BBN.COM and hand the message over ๐Ÿ“จ. Honestly that system broke down in certain situations, like with certain UUCP and CSNET hosts that weren't directly attached to the Internet ๐Ÿ’€. Those hosts got handled as special cases in configuration files. For example, most mailers were set up to automatically forward mail addressed to a CSNET host to CSNET-RELAY.ARPA ๐Ÿ”ฅ.

With domains, you can't just open a connection to LOKI.BBN.COM anymore ๐Ÿ™…โ€โ™€๏ธ. You have to ask the domain system where messages to LOKI.BBN.COM should actually be delivered โœจ. And the domain system might point the mailer at an entirely different host, like SH.CS.NET ๐ŸŒˆ. Or, in a more complicated situation, the mailer might find out it has a choice of routes to LOKI.BBN.COM ๐Ÿ‘‘. This memo is basically a set of guidelines for how mailers should behave in this more complex world ๐Ÿซถ.

Readers are expected to be familiar with RFCs 882 and 883, plus the updates to them, like RFC-973 ๐Ÿค“.


What the Domain Servers Know ๐Ÿ’…

The domain servers store information as a series of resource records (RRs) ๐Ÿ“š. Each one holds a specific piece of information about a domain name, which is usually a host but not always ๐ŸŒท. The simplest way to picture an RR is as a typed pair of data: a domain name matched with relevant data, plus some extra type info so systems can tell when it's relevant ๐ŸŽ€.

For message routing, the system stores MX RRs ๐Ÿ’Œ. Each MX matches a domain name with two pieces of data: a preference value, which is an unsigned 16-bit integer, and the name of a host ๐Ÿฆ‹. The preference number tells the mailer what order to try the MX hosts in, and the lowest numbered MX gets tried first ๐Ÿฅ‡. Multiple MXs can share the same preference, and when they do, they have the same priority ๐Ÿ“.

The servers also store some other RR types that mailers might run into or decide to use ๐Ÿ‘€. One is the canonical name (CNAME) RR, which just says that the domain name you asked about is actually an alias for another domain name, the proper or canonical one ๐Ÿงš. The other is the Well Known Service (WKS) RR, which holds info about network services, like SMTP, that a given domain name supports ๐ŸŒธ.


General Routing Guidelines ๐ŸŒˆ

Before we get into the nitty gritty of how mailers do routing, it makes sense to get a quick overview of how this memo tackles the routing problem โœจ.

The first big principle comes from how the preference field in MX records is defined, and it exists to stop mail from looping ๐Ÿ”. If the mailer is on a host that's listed as an MX for the destination host, the mailer may only deliver to an MX with a lower preference count than its own host ๐Ÿ‘‘. Main character rule, no loops ๐Ÿ’œ.

Mail can also loop because routing info is out of date or incomplete ๐Ÿ˜ญ. Out-of-date info is only a problem when domain tables change ๐Ÿ”„. The changes won't be known to every affected host until their resolver caches time out โณ. There's no way to make this never happen short of making mailers and their resolvers always send queries to an authoritative server and never use cached data ๐Ÿ™…โ€โ™€๏ธ. That's not practical, though, because getting rid of resolver caching would make mailing inordinately expensive ๐Ÿ’ธ.

Here's the thing though: the out-of-date RR problem shouldn't happen if affected hosts (the ones in the list of MXs) get their resolver caches flushed when a domain table changes ๐Ÿงน. So with proper precautions, mail looping from domain info should be avoidable, without making mailers query authoritative servers ๐Ÿ™Œ. (The right precaution is to check with a host's administrator before adding that host to a list of MXs ๐Ÿ“ž.)

Incomplete data needs some care too when handling domain queries ๐Ÿ‘€. If the answer section of a query is incomplete, critical MX RRs might get left out ๐Ÿ˜ฌ. That can cause mail looping, or a message being wrongly labelled undeliverable ๐Ÿ’€. So mailers may only accept responses from the domain system that have complete answer sections ๐Ÿซถ. This whole problem can be avoided by only using virtual circuits for queries, but since it's likely to be really rare, and datagrams are the preferred way to talk to the domain system, implementors should probably just make sure their mailer repeats a query with virtual circuits if the truncation bit ever gets set ๐Ÿฆ‹.


Determining Where to Send a Message ๐ŸŽ€

The way mailers should decide how to route a message is explained through a scenario: a mailer on a host with domain name LOCAL is trying to deliver a message addressed to the domain name REMOTE ๐Ÿ’Œ. Both LOCAL and REMOTE are assumed to be syntactically correct domain names ๐Ÿง . Also, LOCAL is assumed to be the official name of the host the mailer lives on, so it's not an alias ๐Ÿ .


Issuing a Query ๐Ÿ”

The first step for the mailer at LOCAL is to issue a query for MX RRs for REMOTE ๐Ÿš€. It's strongly urged that this step happens every single time a mailer tries to send a message ๐Ÿ’–. The hope is that changes in the domain database get picked up by mailers quickly, so domain admins can re-route in-transit messages for defective hosts just by updating their domain databases ๐Ÿช„.

Some responses to the query count as errors ๐Ÿšจ:

  • Getting no response to the query. The domain server the mailer queried never sends anything back. (This is different from an answer that has no answers to the query, which isn't an error ๐Ÿ™ˆ.)
  • Getting a response where the truncation field of the header is set. (Remember the incomplete queries bit from above ๐Ÿ‘€.) Mailers may not use responses of this type, and should repeat the query using virtual circuits instead of datagrams ๐Ÿ”.
  • Getting a response where the response code is non-zero ๐Ÿ˜ฌ.

Mailers are expected to do something reasonable when they hit an error ๐Ÿซถ. How each type of error gets handled isn't specified here, but implementors should note that different error types should probably be treated differently ๐ŸŒˆ. For example, a response code of "non-existent domain" should probably make the message get returned to the sender as invalid ๐Ÿ’Œ, while a response code of "server failure" should probably make the message get retried later โฐ.

There's one more special case ๐Ÿ‘‘. If the response contains an answer that's a CNAME RR, it means REMOTE is actually an alias for some other domain name ๐ŸŽญ. The query should be repeated using that canonical domain name ๐Ÿ”.

If the response doesn't contain an error and doesn't contain aliases, its answer section should be a list of MX RRs for the domain name REMOTE (or REMOTE's true domain name, if REMOTE was an alias) ๐Ÿ“‹. The list can be zero length, so an empty answer is fine ๐Ÿฆ‹. The next section explains how this list gets interpreted โœจ.

Interpreting the List of MX RRs โœจ

okay bestie, this section is ONLY about how mailers choose which names to try delivering a message to, working from a list of RRs ๐Ÿ“ฌ It does not cover how delivery actually happens. ๐Ÿซถ

NOTE ๐Ÿ“ Whenever this doc says "delivering a message," it just means the mailer does whatever it needs to do to transfer a message to a remote site, given a domain name for that site. For example, an SMTP mailer will try to get an address for the domain name, which involves another query to the domain system, and then, if it gets an address, connect to the SMTP TCP port. ๐Ÿฆ‹ The actual mechanics of moving the message over the network to the address behind a domain name are not in scope for this memo. ๐ŸŒธ

It's possible the list of MXs in the response to the query will be empty. ๐Ÿ™ˆ This is a special case! If the list is empty, mailers should treat it as if it contained one RR, an MX RR with a preference value of 0 and a host name of REMOTE. (I.e., REMOTE is its only MX.) The mailer should also skip any further processing of the list and attempt to deliver the message to REMOTE. ๐Ÿ’– The idea is that if a domain doesn't advertise anything about a particular name, we give it the benefit of the doubt and try delivery anyway. ๐Ÿซถ

If the list is not empty, the mailer should remove irrelevant RRs from it using the following steps. โœจ Note that the order is significant. ๐Ÿ‘‘

  • For each MX, a WKS query should be issued to see if the domain name listed actually supports the mail service desired. MX RRs which list domain names that do not support the service should be discarded. This step is optional, but strongly encouraged. ๐Ÿ’…
  • If the domain name LOCAL is listed as an MX RR, all MX RRs with a preference value greater than or equal to that of LOCAL's must be discarded. ๐Ÿ™…โ€โ™€๏ธ

After removing the irrelevant RRs, the list can be empty again. ๐Ÿ’€ This is now an error condition, and it can happen in a few ways. The simplest case is that the WKS queries found that none of the listed hosts supports the mail service desired. The message is then deemed undeliverable, though extremely persistent mail systems might want to try delivering to REMOTE's address (if it exists) before returning the message. ๐ŸŒˆ

The more dangerous possibility is that the domain system believes LOCAL is handling messages for REMOTE, but the mailer on LOCAL isn't set up to handle mail for REMOTE. ๐Ÿ˜ญ For example, if the domain system lists LOCAL as the only MX for REMOTE, LOCAL will delete all the entries in the list. But LOCAL is presumably querying the domain system because it didn't know what to do with a message addressed to REMOTE, so clearly something is wrong. ๐Ÿšจ How a mailer handles these situations is somewhat implementation dependent, so it's left to the implementor's discretion. ๐Ÿงš

If the list of MX RRs is not empty, the mailer should try to deliver the message to the MXs in order, lowest preference value first. ๐ŸŽ€ The mailer is required to attempt delivery to the lowest valued MX. Implementors are encouraged to write mailers that try the MXs in order until one of them accepts the message or all of them have been tried. ๐Ÿ”ฅ A somewhat less demanding system, where a fixed number of MXs is tried, is also reasonable. ๐Ÿ“ Note that multiple MXs may share the same preference value. In that case, all MXs with a given value must be tried before any with a higher value are tried. ๐ŸŒธ Also, in the special case where several MXs have the lowest preference value, all of them should be tried before a message is deemed undeliverable. ๐Ÿ’œ


Minor Special Issues ๐Ÿ”

There are a couple of special issues left out of the previous section because they would have complicated the discussion. ๐Ÿ™ƒ They're covered here in no particular order. ๐Ÿฆ‹

Wildcard names, the ones containing the character *, may be used for mail routing. ๐ŸŒˆ There are likely to be servers on the network that simply say any mail to a domain should be routed through a relay. For example, when this RFC was being written, all mail to hosts in the domain IL was routed through RELAY.CS.NET. ๐Ÿ‡ฎ๐Ÿ‡ฑ This is done by creating a wildcard RR that states *.IL has an MX of RELAY.CS.NET. This should be transparent to the mailer, since the domain servers hide this wildcard match. (If it matches *.IL with HUJI.IL, for example, a domain server will return an RR containing HUJI.IL, not *.IL.) โœจ If by some accident a mailer receives an RR with a wildcard domain name in its name or data section, it should discard the RR. ๐Ÿ—‘๏ธ

โš ๏ธ Heads up! The algorithm to delete irrelevant RRs breaks if LOCAL has an alias and that alias is listed in the MX records for REMOTE. (E.g., REMOTE has an MX of ALIAS, where ALIAS has a CNAME of LOCAL.) This can be avoided if aliases are never used in the data section of MX RRs. ๐Ÿ’…

Implementors should understand that the query, and the interpretation of the query, is only performed for REMOTE. It is not repeated for the MX RRs listed for REMOTE. ๐Ÿง  You cannot try to support more extravagant mail routing by building a chain of MXs. (E.g., UNIX.BBN.COM is an MX for RELAY.CS.NET, and RELAY.CS.NET is an MX for all the hosts in .IL, but this does not mean UNIX.BBN.COM accepts any responsibility for mail for .IL.) ๐Ÿ™…โ€โ™€๏ธ No chains, bestie!

Finally, this is a standard for routing on the Internet. Mailers serving hosts that lie on multiple networks will presumably have to make some decisions about which network to route through. ๐Ÿ›ฃ๏ธ That decision-making is outside the scope of this memo, although mailers may well use the domain system to help them decide. ๐ŸŒท However, once a mailer decides to deliver a message via the Internet, it must apply these rules to route the message. ๐Ÿ‘‘


Examples ๐ŸŽ€

To illustrate the discussion above, here are three examples of how mailers should route messages. ๐Ÿ’– All of them work with the following database:

A.EXAMPLE.ORG    IN    MX    10    A.EXAMPLE.ORG
A.EXAMPLE.ORG    IN    MX    15    B.EXAMPLE.ORG
A.EXAMPLE.ORG    IN    MX    20    C.EXAMPLE.ORG
A.EXAMPLE.ORG    IN    WKS   10.0.0.1    TCP    SMTP

B.EXAMPLE.ORG    IN    MX    0      B.EXAMPLE.ORG
B.EXAMPLE.ORG    IN    MX    10     C.EXAMPLE.ORG
B.EXAMPLE.ORG    IN    WKS   10.0.0.2    TCP    SMTP

C.EXAMPLE.ORG    IN    MX    0     C.EXAMPLE.ORG
C.EXAMPLE.ORG    IN    WKS   10.0.0.3    TCP    SMTP

D.EXAMPLE.ORG    IN    MX    0     D.EXAMPLE.ORG
D.EXAMPLE.ORG    IN    MX    0     C.EXAMPLE.ORG
D.EXAMPLE.ORG    IN    WKS   10.0.0.4    TCP    SMTP

Example one ๐Ÿฆ‹ An SMTP mailer on D.EXAMPLE.ORG is trying to deliver a message addressed to A.EXAMPLE.ORG. From the answer to its query, it learns that A.EXAMPLE.ORG has three MX RRs. D.EXAMPLE.ORG isn't one of those MX RRs, and all three MXs support SMTP mail (according to the WKS entries), so none of the MXs get eliminated. ๐Ÿ™Œ The mailer is obliged to try delivering to A.EXAMPLE.ORG as the lowest valued MX. If it can't reach A.EXAMPLE.ORG, it can (but isn't required to) try B.EXAMPLE.ORG. And if B.EXAMPLE.ORG isn't responding, it can try C.EXAMPLE.ORG. ๐ŸŒˆ

Example two ๐ŸŒธ This time the mailer is on B.EXAMPLE.ORG, and it's again trying to deliver a message addressed to A.EXAMPLE.ORG. There are once again three MX RRs for A.EXAMPLE.ORG, but here the mailer must discard the RRs for itself and for C.EXAMPLE.ORG, because the MX RR for C.EXAMPLE.ORG has a higher preference value than the RR for B.EXAMPLE.ORG. ๐Ÿซฃ That leaves only the RR for A.EXAMPLE.ORG, so the mailer can only try delivery to A.EXAMPLE.ORG. ๐ŸŽฏ

Example three ๐Ÿ’œ Last one! Consider a mailer on A.EXAMPLE.ORG trying to deliver a message to D.EXAMPLE.ORG. In this case there are only two MX RRs, both with the same preference value. Either MX will accept messages for D.EXAMPLE.ORG. ๐Ÿ“ The mailer should try one MX first (which one is up to the mailer, though D.EXAMPLE.ORG seems most reasonable), and if that delivery fails, it should try the other MX (e.g., C.EXAMPLE.ORG). ๐Ÿงšโœจ

๐Ÿ“ฆ where this page comes from