How is DNS resolved for email addresses

domain-name-systememail

If I send an e-mail to gus@example.com, how does my e-mail client find out what IP address to send the e-mail to? I understand it would do a DNS lookup for example.com, but I want to know what records would be used exactly.

I can send e-mail successfully to one of my domains, gus@echochess.com, and there are no MX records. I am assuming it is using the A record here, but what if I wanted to have a different mail server handle emails, with a different IP?

Best Answer

The answer is in RFC 5321

The lookup first attempts to locate an MX record associated with the name. If a CNAME record is found, the resulting name is processed as if it were the initial name. If a non-existent domain error is returned, this situation MUST be reported as an error. If a temporary error is returned, the message MUST be queued and retried later (see Section 4.5.4.1). If an empty list of MXs is returned, the address is treated as if it was associated with an implicit MX RR, with a preference of 0, pointing to that host. If MX records are present, but none of them are usable, or the implicit MX is unusable, this situation MUST be reported as an error.

To make it a bit more human-readable, and assuming the domain example.com:

  1. Mailserver asks for an MX-record for example.com

  2. a. If there is one or more MX-records, choose the one with the lowest preference. Remember this for step 3.

    b. If there isn't one, ddecide that example.com is acting MX record with lowest preference. Remember this for step 3.

  3. Resolve the MX record to its matching A record and contact that host

So as long as you don't have a specific MX record, your A record will be used as an MX record. Once you do setup an MX record, that one will be used instead.

Related Topic