SMTP
ActiveSimple Mail Transfer Protocol is the standard protocol for sending and relaying email across the internet. SMTP handles the transfer of messages from mail clients to servers (submission) and from server to server (relay). Defined by RFC 5321, SMTP uses a command-response model with 3-digit reply codes to signal success, failure, or error.
In one line
SMTP (Simple Mail Transfer Protocol) is defined by RFC 5321 (2008) and runs on ports 25 (server-to-server relay), 587 (client submission, STARTTLS), and 465 (submissions with implicit TLS). The protocol uses a text command-response model: EHLO, MAIL FROM, RCPT TO, DATA, QUIT. Reply codes follow the 2xx/3xx/4xx/5xx convention – 250 OK confirms acceptance. SMTP only sends mail; IMAP and POP3 retrieve it.
Quick Reference
| Field | Size | Description |
|---|---|---|
| Port 25 | SMTP relay | Server-to-server MTA relay. Blocked by most ISPs for residential IPs to prevent spam. Should not be used for client submission. |
| Port 587 | MSA submission | Mail Submission Agent port (RFC 6409). Used by mail clients (Outlook, Thunderbird) with STARTTLS + AUTH. Current standard for client submission. |
| Port 465 | SMTPS (implicit TLS) | Originally registered for SSL-wrapped SMTP. Deprecated by RFC 2487, then re-registered by RFC 8314 (2018) as submissions port with implicit TLS. |
| EHLO | Handshake | Extended HELO. Client announces its domain. Server responds with 250 and lists supported extensions (STARTTLS, AUTH, SIZE, 8BITMIME). |
| STARTTLS | Upgrade command | RFC 3207. Client sends STARTTLS after EHLO; server responds 220; both parties begin TLS negotiation over the existing connection. |
| AUTH | Authentication | ESMTP AUTH extension. Mechanisms: PLAIN (base64 user:pass), LOGIN, CRAM-MD5, XOAUTH2 (Gmail/OAuth). Required on port 587. |
| Reply codes | 3-digit | 2xx = Success. 3xx = Intermediate (send more data). 4xx = Transient failure (retry). 5xx = Permanent failure (do not retry). |
| DATA | Message transfer | Followed by CRLF.CRLF to terminate. Lines starting with '.' must be dot-stuffed (prepend extra '.'). Server responds 250 when message is queued. |
Key Characteristics
Store-and-forward
SMTP is a store-and-forward protocol. MTAs queue messages and retry delivery over time. RFC 5321 recommends retry intervals with at least 4–5 day persistence before returning a bounce.
AUTH required at 587
Port 587 requires SMTP AUTH before MAIL FROM. This prevents open relay abuse. Modern mail providers enforce DKIM signing and SPF/DMARC validation in addition to AUTH.
Send-only protocol
SMTP only transfers messages to servers. It cannot retrieve messages from a mailbox. Use IMAP (RFC 9051) or POP3 (RFC 1939) to retrieve mail from a server.
7-bit ASCII legacy
Original SMTP is 7-bit ASCII only. The 8BITMIME extension (RFC 6152) allows 8-bit content. Non-ASCII headers and addresses require RFC 6531 (SMTPUTF8 extension) for internationalization.
Message Format
# SMTP session: client submission via port 587 S: 220 mail.example.com ESMTP Postfix
C: EHLO client.example.com
S: 250-mail.example.com
S: 250-SIZE 52428800
S: 250-STARTTLS
S: 250-AUTH LOGIN PLAIN
S: 250 8BITMIME
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
# [TLS handshake occurs here]
C: EHLO client.example.com
C: AUTH PLAIN AGFsaWNlAHBhc3N3b3Jk # base64("\0alice\0password")
S: 235 2.7.0 Authentication successfulC: MAIL FROM:<[email protected]>
S: 250 2.1.0 Ok
C: RCPT TO:<[email protected]>
S: 250 2.1.5 Ok
C: RCPT TO:<[email protected]>
S: 550 5.1.1 User unknown # permanent failure for this recipient
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: [email protected]
C: To: [email protected]
C: Subject: Hello
C:
C: Message body here.
C: .
S: 250 2.0.0 Ok: queued as ABC123
C: QUIT
S: 221 2.0.0 Bye