HTTPfy
The Journey of an Email: How MX Records Route Your Message

The Journey of an Email: How MX Records Route Your Message

Alice works at example.org and writes to Bob at example.com. She clicks Send, and about two seconds later the message shows up in Bob's inbox. In those two seconds her message passes through at least four programs, one DNS lookup and two separate network connections. This post follows it hop by hop, so you know where to look when a message goes missing.

Hop 1: The mail client submits the message

Alice writes in a mail user agent (MUA): Thunderbird, Apple Mail, Outlook, or a phone app. The MUA doesn't deliver mail itself. It hands the message to her provider's submission server, called the mail submission agent (MSA).

Submission uses one of two ports:

  • Port 587 (RFC 6409). The client connects in plain text, sends STARTTLS to upgrade to an encrypted session, then logs in with AUTH.
  • Port 465. The client opens TLS from the first byte. RFC 8314 recommends this "implicit TLS" mode for submission.

Port 25 is for server-to-server traffic. Most home ISPs and cloud providers block outbound port 25 from customer machines, which is why a desktop client configured for port 25 often times out.

The MSA checks Alice's password, confirms she may send as [email protected], and adds headers the client left out, such as Message-ID and Date. Her provider's outbound server then signs the message with DKIM, so receivers can verify it came from example.org and nobody altered it on the way.

A laptop connected to an outbound mail server through an encrypted channel with a padlock

Hop 2: The outbound server looks up the MX records

Alice's outbound server, the mail transfer agent (MTA), now needs to find Bob's mail server. It takes the part of the address after the @ and asks DNS for its MX records:

$ dig MX example.com +noall +answer
example.com.   3600  IN  MX  10 mx1.example.com.
example.com.   3600  IN  MX  20 mx2.example.com.

The MTA sorts the hosts by preference, lowest first, and resolves mx1.example.com to an IP address with an A or AAAA query. If the domain had no MX records at all, the MTA would fall back to the A or AAAA record of example.com itself (RFC 5321 section 5.1). If it found MX 0 ., a null MX, it would stop and bounce the message: Bob's domain accepts no mail.

You can check any domain's MX records with our MX lookup tool, or with dig +short MX example.com from a terminal.

Hop 3: Two servers talk SMTP

The MTA opens a TCP connection to port 25 on mx1.example.com. If that host doesn't answer, it tries mx2. If neither answers, it queues the message and retries for up to five days (the Postfix default), before it gives up and sends Alice a bounce.

When mx1 answers, the two servers hold a short text conversation. Lines from Bob's server start with a three-digit code:

S: 220 mx1.example.com ESMTP
C: EHLO out.example.org
S: 250-mx1.example.com
S: 250-PIPELINING
S: 250-SIZE 52428800
S: 250-STARTTLS
S: 250 8BITMIME
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
   (TLS handshake, then the client sends EHLO again)
C: MAIL FROM:<[email protected]>
S: 250 2.1.0 Ok
C: RCPT TO:<[email protected]>
S: 250 2.1.5 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: (headers and body, ending with a line holding one dot)
S: 250 2.0.0 Ok: queued as 4XyZ1k2Lm9
C: QUIT
S: 221 2.0.0 Bye

The codes tell the sender what to do next. A 2xx code means success. A 4xx code means "try again later", and the sender keeps the message in its queue. A 5xx code means a permanent failure, and the sender bounces the message to Alice at once.

STARTTLS on port 25 is opportunistic. If Bob's server didn't offer it, or an attacker stripped it from the reply, most senders would deliver in plain text. Domains that want encryption enforced publish an MTA-STS policy (RFC 8461) or DANE records (RFC 7672), and senders that support them refuse to deliver without valid TLS.

Note the two sender addresses. MAIL FROM is the envelope sender, where bounces go. The From: header inside the message is what Bob sees in his mail app. They often match, but mailing lists and newsletter platforms set them differently, and that difference matters for the next hop.

Hop 4: The receiving server decides whether to accept

Bob's server runs most of its checks during the SMTP conversation, so it can reject a message with a 5xx code before taking responsibility for it:

  • Connection checks. Does the sending IP appear on a blocklist such as Spamhaus? Does it have a reverse DNS (PTR) name that matches its forward record?
  • SPF (RFC 7208). Is out.example.org's IP listed in the SPF record for the MAIL FROM domain?
  • DKIM. Does the signature verify against the public key at selector._domainkey.example.org?
  • DMARC (RFC 9989, which replaced RFC 7489 in 2026). Does SPF or DKIM pass for a domain that matches the visible From: header? If not, example.org's DMARC policy tells Bob's server to accept, quarantine or reject.
  • Content filtering. A spam engine scores the body, links and attachments.

Once it accepts the message, Bob's server adds a Received: header to the top of it:

Received: from out.example.org (out.example.org [198.51.100.7])
    by mx1.example.com (Postfix) with ESMTPS id 4XyZ1k2Lm9
    for <[email protected]>; Tue, 10 Nov 2026 09:14:03 +0000

Every server that handles the message adds one of these. To trace a message, read the Received: headers from the bottom up: the lowest one is the first hop, the top one is the last. A big jump in timestamps between two headers shows you where the delay happened.

A receiving mail server passing messages through a filter into inbox trays, with one rejected message falling away

Hop 5: The message lands in the mailbox

The MTA hands the message to a mail delivery agent (MDA), often Dovecot, over LMTP. The MDA runs Bob's filtering rules (Sieve scripts, or the "move newsletters to a folder" rules he set up in webmail), picks the inbox or the junk folder, and writes the message to disk.

Bob's phone then fetches it with IMAP on port 993, or the webmail page reads it straight from the store. Hosted providers such as Gmail and Microsoft 365 run all of these roles inside their own systems, but the hops from Alice's outbound server to Bob's MX look the same.

Where messages go missing

Each hop fails in its own way, and the symptom points you to the hop:

  • Alice's client says "cannot connect" or "authentication failed." Hop 1. Check the port (587 or 465), the TLS setting and the password.
  • Alice gets a bounce that says "domain not found" or "no mail host." Hop 2. Bob's domain has no MX, a null MX, or an MX target with no A record. Run dig MX example.com and dig A mx1.example.com.
  • The message sits in Alice's queue for hours. Hop 3. Bob's MX hosts don't answer on port 25, or they return 4xx codes. A firewall change or a new MX that hasn't come up yet causes this.
  • Alice gets a 5xx bounce mentioning SPF, DKIM or DMARC. Hop 4. Fix example.org's sending records. Bob's MX is working.
  • The message arrived but Bob can't find it. Hop 5. Check his junk folder and filter rules, then search the server logs for the queue ID from the 250 reply.

When you change MX records, remember that senders cache the old answer for the record's TTL. Lower the TTL to 300 seconds a day before a migration, and keep the old server accepting mail until the old TTL has passed.