skip to content

In a hand-driven SMTP test of your staging MTA on port 25, which commands run from EHLO to QUIT, and how does DATA end?

level: middleimportance: must knowfreq 44%

answer

  1. greeting first, then introduce yourself
  2. envelope commands before the text
  3. 354 means start typing the message
  4. a line holding only a dot
  5. leading dots get doubled

basics

~20 s

After the 220 greeting the client sends EHLO, MAIL FROM, one RCPT TO per recipient and DATA, then the message ended by a line holding only a dot, then QUIT. Replies: 250 to each step, 354 after DATA, 221 after QUIT.

solid answer

~40 s

The server speaks first with `220`. The client sends `EHLO` with its host name and gets a multiline `250` listing the extensions; `HELO` is the fallback for a server that does not recognise `EHLO`. Then `MAIL FROM:<address>` opens the transaction, one `RCPT TO:<address>` per recipient follows, each answered `250` or refused, and `DATA` gets `354`. The client sends the header fields, a blank line and the body, and ends the data with a line containing only `.`, which on the wire is `CR LF . CR LF`; any text line that starts with a dot gets a second dot first (RFC 5321 4.5.2). The server answers `250` when it has taken responsibility for the message. `RSET` abandons the transaction without closing, `NOOP` just returns `250`, and `QUIT` gets `221` and the connection closes.

go deeper

for a junior

Recall the order EHLO, MAIL FROM, RCPT TO, DATA, the dot line, QUIT, and the reply each gets: 250, 354, 250, 221.

for a middle

Explain the lone dot and dot-stuffing, why EHLO and not HELO, what RSET and NOOP do, and why message text waits for 354.

for a senior

Diagnose a stall after DATA: a client that never sends the standard end of data, a slow filter inside the 10-minute window, or a rejection after the dot.

for a principal

Decide which test sessions your team may run against production MXs, and insist the tests use ordinary messages to mailboxes you own.

## One message, command by command An SMTP session (RFC 5321) is a strict question-and-answer exchange over TCP. Testing your own staging server by hand, with an ordinary message to a mailbox you control, looks like this (`C:` is you, `S:` the server): 1. `S: 220 mail.example.com ESMTP` — the **greeting**; the server speaks first. 2. `C: EHLO client.example.net` — introduce yourself and ask for the extension list. 3. `S: 250-mail.example.com`, `S: 250-PIPELINING`, `S: 250-SIZE 10240000`, `S: 250 ENHANCEDSTATUSCODES` — a multiline reply; the space after the last `250` ends it. 4. `C: MAIL FROM:<[email protected]>` then `S: 250 2.1.0 Ok` — the **reverse-path** opens a mail transaction. 5. `C: RCPT TO:<[email protected]>` then `S: 250 2.1.5 Ok` — one **forward-path** per recipient; each may be accepted or refused on its own. 6. `C: DATA` then `S: 354 End data with <CR><LF>.<CR><LF>` — the only intermediate reply in core SMTP. 7. `C:` the header fields, an empty line, the body, and a line holding a single `.` 8. `S: 250 2.0.0 Ok: queued` — the server now owns the message. 9. `C: QUIT` then `S: 221 2.0.0 Bye` — the server closes the connection. What the `MAIL FROM` and `RCPT TO` addresses mean against the `From:` and `To:` header fields the message carries is a separate subject, covered with the envelope and the headers. ## EHLO against HELO - `EHLO` says the client understands **service extensions** and asks the server to list them; the answer is the server's capability list. - `HELO` is the original greeting. RFC 5321 lets older systems, and clients that need no extensions, use it, and a server **MUST NOT** return the extended response to `HELO`. - If a server answers `EHLO` with "command not recognized", the client SHOULD be able to fall back to `HELO`. ## How the data ends, and dot-stuffing The message text travels on the same channel as the commands, so SMTP needs a marker for where it stops. RFC 5321 uses a line containing only a period: the sequence `CR LF . CR LF`. To let a message contain a line that starts with a period, the **transparency** procedure (4.5.2) applies: - before sending a line, the client checks its first character; if it is a period, it inserts one more; - the server treats a line holding a single period as the end of the data, and removes the first period from any other line that starts with one. This is called **dot-stuffing**. RFC 5321 2.3.8 also fixes what a line is: data characters ended by `CR LF`, and conforming implementations MUST NOT recognise any other sequence as a line terminator. ## RSET, NOOP and QUIT - `RSET` aborts the current transaction: sender, recipients and data are discarded, the server replies `250`, and the connection stays open for a new `MAIL FROM`. A server MUST NOT close the connection because of `RSET`. A new `EHLO` also aborts the transaction, but RFC 5321 notes that `RSET` is normally more efficient. - `NOOP` changes nothing and returns `250`; it keeps an idle session alive or checks that the server still answers. - `QUIT` asks for `221` and the close. A client should not drop the connection without it. A `DATA` sent with no accepted recipient may get `503` or `554`, and message text MUST NOT be sent unless `354` arrived. ## When a session stalls after DATA Suppose one client's messages hang after `DATA` against your staging MTA. Check, in order: 1. **Did the end of data arrive?** If the client never sends the standard `CR LF . CR LF`, the server keeps waiting for more text. A client that ends its lines with a bare LF is the usual cause. Postfix's `smtpd_forbid_bare_newline = normalize`, the default from Postfix 3.9, still accepts lines that end in a bare LF but requires the standard end-of-data sequence, so the Postfix documentation warns that mail from such a client is not received: the server is still waiting for the end of the data. 2. **Is the server busy after the dot?** RFC 5321 gives the client 10 minutes to wait for the final `250`, because the server may be filtering or delivering; a client that gives up sooner may send the message twice. 3. **Did the server reject the text?** A `552` for size or a `554` for policy after the dot is an answer, not a stall; read its enhanced code. A hand-driven test can be such a client itself, because some terminal clients send only LF when you press Enter. Postfix's `smtpd_forbid_bare_newline_exclusions` defaults to `$mynetworks`, so a test from inside that range is exempt while a test from outside meets the full rule. ## Limits worth knowing | Item | RFC 5321 value | |---|---| | command line, including `CR LF` | 512 octets | | reply line, including `CR LF` | 512 octets | | text line, including `CR LF` | 1000 octets | | wait for the `220` greeting | 5 minutes | | wait for the reply to `DATA` (the `354`) | 2 minutes | | wait for the `250` after the final dot | 10 minutes | | server waiting for the next command | at least 5 minutes | Extensions can raise the line limits, and the server's `EHLO` answer says which extensions are in play.

  • Why can the server not simply end the data at the first line holding a dot without dot-stuffing?
    Because the message itself may contain such a line, for example a quoted dot or a signature separator. Without transparency the server would cut the message there and treat the rest as commands. RFC 5321 4.5.2 has the client double any leading dot and the server strip it, so only an unstuffed single-dot line ends the data.
  • What happens when one RCPT TO is refused but another is accepted?
    The transaction continues for the accepted recipients: each `RCPT TO` gets its own reply, `DATA` can proceed as long as at least one recipient was accepted, and the message goes only to those. A `DATA` after every recipient was refused may get `503` or `554`, and without a `354` the client must not send the text.
  • When would you use RSET instead of QUIT in a hand-driven test?
    When you want to abandon the current transaction, say after a typo in `RCPT TO`, but keep the connection and its `EHLO` state. `RSET` discards sender, recipients and data and returns `250`; you can start again with `MAIL FROM`. `QUIT` ends the whole session with `221`.

  • The message ends when the client closes the connection.
  • RCPT TO comes before MAIL FROM in a transaction.
  • A 250 to RCPT TO means the message has been delivered.
  • RSET closes the connection just as QUIT does.
  • Any line feed is accepted as a line ending by a conforming server.
  • A line in the body that starts with a dot is sent unchanged.