Most sites will usually want to direct all in-bound 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:
foobar.com IN MX 5 mailhub.foobar.comThis 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.