SMTP

SMTP

Simple Mail Transfer Protocol. The protocol email clients use to send outbound messages to mail servers, and that mail servers use to relay messages to each other. Defined in RFC 5321 (with extensions in many other RFCs). Dates to 1982.

SMTP is a one-way push protocol: you connect, you submit a message, you disconnect. Reading mail uses IMAP or POP3 — different protocol, different port.

Wire format

A line-based ASCII protocol. Client issues commands; server responds with 3-digit status codes.

S: 220 mail.example.com ESMTP Postfix
C: HELO client.example.com
S: 250 mail.example.com
C: MAIL FROM:<alice@example.com>
S: 250 OK
C: RCPT TO:<bob@example.com>
S: 250 OK
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: alice@example.com
C: To: bob@example.com
C: Subject: hi
C:
C: Hello, Bob.
C: .
S: 250 OK
C: QUIT
S: 221 Bye

The DATA block is the entire RFC 5322 message — headers, blank line, body. Encoded per MIME for anything richer than ASCII text.

Ports

Authentication

Modern SMTP submission requires authentication. Common mechanisms:

TLS modes

What mxr does

Per Mxr's crates/provider-smtp/src/lib.rs:

Common pitfalls

SMTP vs alternatives

See also