How Email Moves
Four programs, two protocols, and where a domain's mail goes.
Sending mail is four lines of library code. Having it arrive is the subject.
The journey of one message
Your client hands the message to a submission server, which looks up the recipient’s domain and delivers it to that domain’s mail exchanger.
Nobody is waiting at the other end. Each hop stores the message and passes it on when it can, so a delay is minutes rather than milliseconds.
MUA, MSA, MTA, MDA
Four roles; you talk to two:
| Role | Is | You |
|---|---|---|
| MUA | your mail client | use it |
| MSA | the submission server you authenticate to | send through it |
| MTA | a server relaying between domains | never touch it |
| MDA | the thing that files mail in a mailbox | never touch it |
Sending and receiving are different protocols: SMTP pushes a message towards a mailbox, IMAP and POP3 pull it back out — chapter 7.
The ports
Five numbers, three of which matter to you:
| Port | For | Encryption |
|---|---|---|
| 25 | server to server | STARTTLS, optional |
| 465 | submission | TLS from the first byte |
| 587 | submission | STARTTLS, expected |
| 143 | IMAP | STARTTLS |
| 993 | IMAP | TLS from the first byte |
A server to practise against
One command gives an SMTP server that accepts everything, plus a web UI:
docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhogConnect to it and it introduces itself before you say anything:
QUITSay EHLO and it lists what it supports:
EHLO test.local
QUITNothing here is sent to a real person. MailHog accepts every message and delivers none, so you cannot accidentally mail a stranger.
The parts of an address
[email protected] is a local part, an @, and a domain. The local part belongs entirely
to the receiving server; only the domain is looked up:
dig +short MX gmail.com | sort -n | head -1 | cut -d' ' -f2MX records
The domain says where its mail goes, lowest number first:
dig +short MX gmail.com | sort -nEqual numbers spread load between hosts:
dig +short MX cloudflare.com | sort -n | grep '^10 'No MX record at all falls back to the A record — the web server gets the mail:
dig +short MX neverssl.comdig +short A neverssl.comA single dot means something different — the domain accepts no mail at all:
dig +short MX example.comThat is a null MX, and it has to be said explicitly — silence means “try the web server”.
Reverse DNS
An address maps back to a name, and receiving servers check it:
dig +short -x 8.8.8.8What 250 Ok does not mean
Send a message and it is accepted immediately:
EHLO test.local
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
DATA
Subject: Test
hi
.
QUITqueued as is the whole promise: accepted for delivery, not delivered.