Skip to content
OEWER Tools
Technology

How Email Travels: SMTP, MX Records, IMAP and POP3

4 min readBy OEWER Team

Email passes through several programs and servers between sender and inbox. Here is the route, what MX records and SMTP do, and how IMAP differs from POP3.

In this article
  1. The cast of programs
  2. Step 1: handing the message over
  3. Step 2: finding the destination with MX records
  4. Step 3: SMTP conversation
  5. Step 4: collecting the message
  6. A short history
  7. What this article does not cover
  8. Sources

An email moves in two stages. First it is pushed from the sender's mail program to the recipient's mail server using SMTP. Then the recipient's own program collects it using IMAP or POP3. In between, the DNS system tells the sending server where the recipient's mail server lives, through a record type called MX. Knowing these steps makes sense of settings screens and error messages.

The cast of programs

Wikipedia's article on email follows a message from a sender, Alice, to a recipient, Bob. Several roles appear:

  • MUA (mail user agent): the email app or webmail page you use.
  • MSA (mail submission agent): the outgoing server that accepts the message from the app.
  • MTA (message transfer agent): a server that passes mail onward using SMTP.
  • MDA (message delivery agent): the final step that places the message in the recipient's mailbox.

In practice one service often performs several of these roles, but the model helps explain what happens.

Step 1: handing the message over

Alice's app sends the message to her outgoing server using the submission protocol, which Wikipedia describes as a profile of SMTP, the Simple Mail Transfer Protocol. The server reads the recipient's address from the SMTP envelope, which is the delivery information, not the header lines that appear in the message. It uses the part after the @ sign to decide where to send the mail.

Step 2: finding the destination with MX records

The sending server asks DNS for the MX (mail exchanger) records of the recipient's domain. These name the servers that accept mail for that domain. RFC 5321, the main SMTP standard, says intermediate hosts are normally found through MX records rather than through the sender spelling out a route. A domain can list more than one MX record, and the priority numbers let a backup take over if the first server is down. This detail comes from general descriptions of DNS mail routing.

Step 3: SMTP conversation

RFC 5321 describes SMTP as a lock-step dialogue. The client sends a command, and the server replies with a three-digit code. Examples listed in the standard include 220 for the server's greeting, 250 for OK, 354 to say it is ready for the message text, 450 and 451 for temporary failures, and 550 when the mailbox is not found or relay is refused. The first digit tells the client the broad outcome, which is why a temporary failure can be retried later and a permanent one is returned to the sender as a bounce.

The receiving server may be the final destination or a relay that becomes a client itself and forwards the message to the next server. According to Wikipedia, the message can pass through other MTAs before reaching its destination. RFC 5321 was published in October 2008 by J. Klensin and replaced earlier standards including RFC 821 and RFC 2821.

Step 4: collecting the message

Delivery to the mailbox is not the same as reading it. Bob's app fetches the message with one of two protocols.

  • POP3: the app downloads messages, and Wikipedia notes they are often deleted from the server afterwards. It allows reading offline.
  • IMAP: the mailbox stays on the server in folders. Wikipedia says the app first shows message headers and downloads specific messages on request, so one mailbox can be managed from several devices.

This is why a message you delete in an IMAP app usually disappears on your other devices too, while with POP3 the behaviour depends on settings.

A short history

According to Wikipedia, the first network mail on the ARPANET was sent in 1971 and introduced the @ address style. The conventions for To, From, CC and BCC fields began with RFC 680 in 1975. SMTP was implemented on the ARPANET in 1983. The message format standard RFC 822 dates to 1982 and was later replaced by RFC 2822 in 2001 and RFC 5322 in 2008. The article says the suite of SMTP, POP3 and IMAP became the standard after restrictions on commercial traffic on the Internet ended in 1995.

What this article does not cover

Modern mail also uses sender checks and encryption to fight spam and forgery. The sources I opened for this article did not explain those systems in detail, so they are left out. Port numbers also vary by provider and are not given here; your provider's help page lists the right settings for your account.

Sources

This article was written with AI assistance. How we research and check our articles.

Share

Email

Keep reading