RFC 5321: SMTP: Transferring email between servers
Summary
In October 2008, John Klensin consolidated the Simple Mail Transfer Protocol, which mail servers use to pass on messages, in RFC 5321. The document replaces RFC 2821 and with it the line that began with Jon Postel’s RFC 821 of August 1982. SMTP is a store-and-forward system with queues, reply codes and retries that originally worked without encryption or sender verification.
Queues instead of direct connections
A mail server accepts a message and thereby takes on the responsibility of delivering it or reporting an error back. If the destination cannot be reached, the message stays in the queue. RFC 5321 recommends retrying after 30 minutes at the earliest and giving up only after at least four to five days.
Reply codes separate temporary errors (4xx), after which delivery is retried, from permanent ones (5xx), which lead to a bounce. The sender determines the destination through MX records in DNS; if there are none, the address of the domain name counts as an implicit MX. Since RFC 7505 from 2015, a domain can explicitly declare with a null MX that it accepts no mail.
What SMTP itself does not cover
With EHLO instead of HELO, servers can announce extensions, and RFC 5321 requires servers to support EHLO. Encryption via STARTTLS (RFC 3207 from 2002) and sender verification via SPF (RFC 7208) and DKIM (RFC 6376), however, are separate standards that complement SMTP.
Relaying is also described openly at its core: a server may forward mail for other domains. Abuse by spam made open relays a problem in the 1990s; today a server only relays for its own users or domains.
Ideas
- Mail servers take responsibility for accepted messages.
- Queues bridge temporarily unreachable destinations.
- 4xx codes mean retry later, 5xx codes mean reject permanently.
- MX records determine which server accepts mail for a domain.
- Without an MX, the domain’s address counts as an implicit MX.
- EHLO announces extensions and replaces HELO.
Insights
- Email is a federated queueing system; deliverability therefore depends as much on DNS, TLS and reputation as on SMTP itself.
- An open protocol from 1982 became more secure through additions rather than replacement, which preserved its reach but complicated its configuration.
Facts
- RFC 5321 appeared in October 2008 and replaces RFC 821, RFC 974, RFC 1869 and RFC 2821.
- A text line may be at most 1,000 characters long including CRLF.
- At least 30 minutes should pass between delivery attempts, and delivery is abandoned after at least four to five days.
- The message format itself is described in the companion document RFC 5322.
References
- RFC 5321: Simple Mail Transfer Protocol
- RFC 5322: Internet Message Format (2008)
- RFC 3207: SMTP Service Extension for Secure SMTP over TLS (2002)
- RFC 7505: A Null MX No Service Resource Record (2015)
Remarks
- RFC 5321 and RFC 5322 are Draft Standards; many mail server manuals refer directly to these two documents for reply codes and timing.
Recommendations
- Regularly evaluate a mail server’s queue, bounces and delivery errors.
- Set up SPF, DKIM and DMARC in addition to SMTP, otherwise messages end up in spam.
- Offer STARTTLS and protect it against downgrade with MTA-STS (RFC 8461) or DANE.
Read the RFC at the RFC Editor
Found a mistake or have something to add? Get in touch.
Links to the original source and the Web Archive open in a new tab.