Skip to main content

4. The SMTP Specifications

This section contains the detailed specifications for SMTP commands, replies, sequencing, trace information, and implementation issues.

4.1. SMTP Commands

4.1.1. Command Semantics and Syntax

SMTP commands are 4-letter (some extended to 8) case-insensitive ASCII words optionally followed by parameters.

Extended HELLO (EHLO) or HELLO (HELO)

Syntax: EHLO domain or HELO domain

The EHLO command initiates an SMTP session and requests service extensions. HELO is the fallback for servers not supporting extensions.

Example:

C: EHLO client.example.com
S: 250-server.example.com
S: 250-SIZE 52428800
S: 250-8BITMIME
S: 250 STARTTLS

MAIL (MAIL FROM)

Syntax: MAIL FROM:<reverse-path> [parameters]

Initiates a mail transaction by specifying the sender.

Example:

C: MAIL FROM:``<[email protected]>``
S: 250 Ok

Parameters: May include SIZE, BODY, AUTH, etc.

RECIPIENT (RCPT TO)

Syntax: RCPT TO:<forward-path> [parameters]

Identifies one recipient of the mail.

Example:

C: RCPT TO:``<[email protected]>``
S: 250 Ok

DATA

Syntax: DATA

Indicates start of message content. Content ends with <CRLF>.<CRLF>.

Example:

C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: [email protected]
C: To: [email protected]
C: Subject: Test
C:
C: Message body here.
C: .
S: 250 Ok: queued as 12345

RESET (RSET)

Syntax: RSET

Aborts current mail transaction and resets buffers.

Example:

C: RSET
S: 250 Ok

VERIFY (VRFY)

Syntax: VRFY string

Verifies that a mailbox exists.

Example:

C: VRFY Jones
S: 250 Fred Jones ``<[email protected]>``

Note: Many servers disable this for security reasons.

EXPAND (EXPN)

Syntax: EXPN string

Expands a mailing list.

Example:

C: EXPN staff
S: 250-Alice ``<[email protected]>``
S: 250 Bob ``<[email protected]>``

HELP

Syntax: HELP [command]

Provides help information.

Example:

C: HELP
S: 214-This server supports the following commands:
S: 214 EHLO MAIL RCPT DATA RSET VRFY HELP QUIT

NO OPERATION (NOOP)

Syntax: NOOP

Does nothing, used to keep connection alive.

Example:

C: NOOP
S: 250 Ok

QUIT

Syntax: QUIT

Terminates the SMTP session.

Example:

C: QUIT
S: 221 server.example.com closing connection

4.1.2. Command Argument Syntax

Commands follow strict syntax rules defined in ABNF (RFC 5234).

Mailbox Format: local-part@domain

  • Local-part: up to 64 characters
  • Domain: fully qualified domain name or address literal

Address Literals:

  • IPv4: [192.0.2.1]
  • IPv6: [IPv6:2001:db8::1]

4.1.3. Address Literals

Address literals are domains enclosed in brackets:

  • [192.0.2.1] - IPv4 address
  • [IPv6:2001:db8::1] - IPv6 address

4.1.4. Order of Commands

Valid command sequences:

  1. Connection: Server sends 220
  2. Greeting: Client sends EHLO/HELO
  3. Transaction: MAIL → RCPT (one or more) → DATA
  4. Termination: QUIT

Invalid sequences result in 503 "Bad sequence of commands" error.

4.1.5. Private-Use Commands

Commands starting with X are reserved for private use and experimentation.

4.2. SMTP Replies

4.2.1. Reply Code Severities and Theory

Reply codes are 3-digit numbers:

  • 2yz: Positive completion
  • 3yz: Positive intermediate
  • 4yz: Transient negative (retry possible)
  • 5yz: Permanent negative (do not retry)

Second digit indicates category:

  • x0z: Syntax
  • x1z: Information
  • x2z: Connections
  • x5z: Mail system

4.2.2. Reply Codes by Function Groups

Connection Establishment:

  • 220: Service ready
  • 421: Service not available

Client Initiation:

  • 250: OK
  • 500: Syntax error
  • 502: Command not implemented

Mail Transactions:

  • 250: OK
  • 354: Start mail input
  • 450/550: Mailbox unavailable
  • 451/551: Error in processing
  • 452/552: Insufficient storage
  • 553: Mailbox name invalid
  • 554: Transaction failed

4.2.3. Reply Codes in Numeric Order

  • 211: System status
  • 214: Help message
  • 220: Service ready
  • 221: Closing connection
  • 250: OK
  • 251: User not local; will forward
  • 252: Cannot VRFY user, but will accept
  • 354: Start mail input
  • 421: Service not available
  • 450: Mailbox unavailable
  • 451: Local error
  • 452: Insufficient storage
  • 455: Server unable to accommodate parameters
  • 500: Syntax error
  • 501: Syntax error in parameters
  • 502: Command not implemented
  • 503: Bad sequence of commands
  • 504: Command parameter not implemented
  • 550: Mailbox unavailable
  • 551: User not local
  • 552: Storage allocation exceeded
  • 553: Mailbox name not allowed
  • 554: Transaction failed
  • 555: Parameters not recognized

4.2.4. Reply Code 502

502 indicates command not implemented. Clients should not retry unimplemented commands.

4.2.5. Reply Codes after DATA and the Subsequent <CRLF>.<CRLF>

After DATA completion:

  • 250: Message accepted
  • 450/550: Mailbox unavailable
  • 451/551: Processing error
  • 452/552: Insufficient storage
  • 554: Transaction failed

4.3. Sequencing of Commands and Replies

4.3.1. Sequencing Overview

SMTP is lock-step: client sends command, waits for reply, then sends next command. Exception: PIPELINING extension allows batching.

4.3.2. Command-Reply Sequences

Minimum Implementation:

S: 220
C: EHLO
S: 250
C: MAIL FROM
S: 250
C: RCPT TO
S: 250
C: DATA
S: 354
C: (message data)
C: .
S: 250
C: QUIT
S: 221

4.4. Trace Information

Each SMTP server adds a Received header field when accepting a message:

Format:

Received: from sender.example.com (host.example.com [192.0.2.1])
by receiver.example.com (Postfix) with ESMTP id 12345
for ``<[email protected]>``; Mon, 24 Dec 2024 10:00:00 +0000 (UTC)

Components:

  • from: Sending host identification
  • by: Receiving host
  • with: Protocol used (SMTP, ESMTP, etc.)
  • for: Recipient address
  • Timestamp

4.5. Additional Implementation Issues

4.5.1. Minimum Implementation

Fully-functional SMTP must support:

  • Commands: EHLO, MAIL, RCPT, DATA, RSET, NOOP, QUIT
  • Reply codes: All standard codes
  • Queueing and retry logic
  • Proper error handling

4.5.2. Transparency

Servers must handle dot-stuffing: lines beginning with . must be escaped as .. during DATA transmission.

4.5.3. Sizes and Timeouts

4.5.3.1. Size Limits and Minimums

Minimum Requirements:

  • Local-part: 64 octets
  • Domain: 255 octets
  • Path: 256 octets
  • Command line: 512 octets
  • Reply line: 512 octets
  • Text line: 1000 octets
  • Recipients buffer: 100 recipients

4.5.3.2. Timeouts

Client Timeouts:

  • Initial 220 message: 5 minutes
  • MAIL command: 5 minutes
  • RCPT command: 5 minutes
  • DATA initiation: 2 minutes
  • Data block: 3 minutes
  • DATA termination: 10 minutes

Server Timeouts:

  • Waiting for command: 5 minutes
  • Waiting for DATA: 10 minutes

4.5.4. Retry Strategies

On transient failures (4yz codes):

  • Retry at least every 30 minutes
  • Continue trying for at least 4-5 days
  • Send warnings to sender at intervals
  • Generate bounce after final failure

4.5.5. Messages with a Null Reverse-Path

Bounce messages use MAIL FROM:<> (null reverse-path) to prevent mail loops. Servers MUST accept null reverse-path but MUST NOT generate bounces for them.