mail.routing.internetMail Routing on the Internet
On the Internet, it depends entirely on the destination host whether any specific mail routing is performed at all. The default is to deliver the message to the destination host directly by looking up its IP address, and leave the actual routing of the data to the IP transport layer.
Most sites will usually want to direct all inbound mail to a highly available mail server that is capable of handling all this traffic, and have it distribute this mail locally. To announce this service, the site publishes a so-called MX record for their local domain in the DNS database. MX stands for Mail Exchanger and basically states that the server host is willing to act as a mail forwarder for all machines in this domain. MX records may also be used to handle traffic for hosts that are not connected to the Internet themselves, like UUCP networks, or company networks with hosts carrying confidential information.
MX records also have a preference associated with them. This is a positive integer. If several mail exchangers exist for one host, the mail transport agent will try to transfer the message to the exchanger with the lowest preference value, and only if this fails will it try a host with a higher value. If the local host is itself a mail exchanger for the destination address, it must not forward messages to any MX hosts with a higher preference than its own; this is a safe way of avoiding mail loops.
Suppose that an organization, say Foobar Inc., want all their mail handled by their machine called mailhub. They will then have an MX record like this in the DNS database:
This announces mailhub.foobar.com as a mail exchanger for foobar.com with a preference value of 5. A host that wishes to deliver a message to firstname.lastname@example.org will check DNS for foobar.com, and finds the MX record pointing at mailhub. If there's no MX with a preference smaller than 5, the message will be delivered to mailhub, which then dispatches it to greenhouse.
The above is really only a sketch of how MX records work. For more information on the mail routing on the Internet, please refer to RFC 974.