2

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?

Gus
  • 21
  • 1
  • 2
  • There are two questions here. Using a different mail server is as simple as setting up another account or changing the mail server of the existing account. Mail clients' behavior differs wildly. Perhaps you can tell us what mail clients you are using, and if you have control over your DNS service. – kmarsh Jan 27 '14 at 15:17

3 Answers3

8

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.

Jenny D
  • 27,780
  • 21
  • 75
  • 114
6

If there is no MX record, an A record is used as a fallback. To achieve what you want, simply set the MX record to your desired destination.

John
  • 9,070
  • 1
  • 29
  • 34
3

First, your client does no DNS lookups. All the lookups are done on the MTA.

The MX record is the preferred DNS record in these cases, but as you stated an A record can stand in its place if no MX records are found (don't count on that being supported by everyone), and if you have no MX record it's very likely that mail from your MTA will be rejected.

NickW
  • 10,263
  • 1
  • 20
  • 27
  • 1
    If using an A record isn't supported, then the sending MTA is **broken** and should be taken out and shot. – Jenny D Jan 27 '14 at 14:59
  • Oh I agree, but I've dealt with remote MTAs who thought 450 == 550, and worse.. – NickW Jan 27 '14 at 15:04
  • So have I... So let me rephrase that. "the MTA should be set on fire and shown around the world as a warning to programmers to read the RFC first". – Jenny D Jan 27 '14 at 15:10
  • You're my kind of sysadmin :) – NickW Jan 27 '14 at 15:12
  • I did email sysadmin/postmaster duty at an ISP for 7 years. I may or may not have some remaining issues :-) – Jenny D Jan 27 '14 at 15:13
  • That's exactly the background I came from, I see we have some of the same "tics" – NickW Jan 27 '14 at 15:28
  • Well. I used to have an axe hanging by my desk. If you were in NANAE or other sysadmin/mail/spam circles in the late 90's/early 2000's, we may have run into one another... – Jenny D Jan 28 '14 at 16:50
  • I frequented most of the lists, but didn't contribute much as I worked in Italy, and a lot of my problems were distinctly italian :D – NickW Jan 28 '14 at 16:55