How a sending server turns MX records into a delivery list
[email protected], it goes through roughly these steps before opening any connection:
- It takes the domain part of the address and asks DNS for its MX records.
- It gets back a set of records. Each one has a preference value, an unsigned 16-bit number from 0 to 65535, and a target hostname.
- It sorts them in ascending order. The lowest number is the most preferred host.
- It groups records with the same preference. Within each group the order is shuffled. RFC 5321, the SMTP standard, recommends that senders randomize here.
- If the sending machine finds its own hostname in the list, it drops its own entry and every entry with an equal or higher number. This prevents mail loops. It is also why a backup MX relays mail onward to the primary instead of sending it back to itself.
- It resolves each remaining hostname to IPv4 (A) and IPv6 (AAAA) addresses, then works through those addresses in that order.
- If a domain has no MX records at all, senders typically fall back to the domain's own A or AAAA address, often called an implicit MX.
- If a domain should never receive mail, a null MX record (preference 0, target a single dot) states that explicitly.
The next host is tried only when the current one fails temporarily
- connection refused
- a timeout
- no route to the host
- a 4xx temporary reply from the receiving server
- A store-and-forward relay. Mail takes an extra hop and may arrive late. If the relay does not know which mailboxes exist, it accepts mail for any address and later bounces the invalid ones. This produces backscatter: bounces sent to forged sender addresses.
- A leftover mailbox server, such as the old host after a migration. Messages land in mailboxes nobody checks anymore.
Equal numbers mean shared load, not a standby
Checking the real order with dig
example.com with your domain and ns1.example-dns.net with one of the nameservers that the NS query returns.
BASH
# MX records as your current resolver sees them
dig +short MX example.com
# Find the authoritative nameservers, then ask one directly (placeholder name)
dig +short NS example.com
dig +norecurse MX example.com @ns1.example-dns.netTEXT
# Sample output format
20 backup.example.com.
10 mail.example.com.mail.example.com is the preferred host even though it is printed second. Read the numbers, not the line order. If two lines share a number, expect senders to split mail between those hosts.
Next, confirm that every target resolves to the address you expect. A preferred host that points at a decommissioned IP will make senders time out on it before moving on. That shows up as slow delivery rather than an obvious error.
BASH
# Each MX target should resolve to the intended server
dig +short A mail.example.com
dig +short AAAA mail.example.com