Bad Sequence of Commands
SMTP 503 Bad Sequence of Commands means the client sent a command at the wrong stage of the conversation. SMTP is a strict state machine: EHLO → MAIL FROM → RCPT TO → DATA → QUIT. Jumping steps – sending DATA before MAIL FROM, RCPT TO before EHLO, or MAIL FROM inside an open transaction – triggers 503. Fix by sending RSET to reset state.
Wire exchange
# DATA without RCPT TO C: MAIL FROM:<[email protected]> S: 250 2.1.0 Ok C: DATA S: 503 5.5.0 Error: need RCPT command # RCPT TO without MAIL FROM C: RCPT TO:<[email protected]> S: 503 5.5.0 Error: need MAIL command # Double MAIL FROM (transaction already open) C: MAIL FROM:<[email protected]> S: 250 2.1.0 Ok C: MAIL FROM:<[email protected]> S: 503 5.5.0 Error: nested MAIL command # Fix: send RSET to reset C: RSET S: 250 2.0.0 Ok C: MAIL FROM:<[email protected]> S: 250 2.1.0 Ok
Details
SMTP enforces a specific command ordering. 503 fires when that order is violated.
The SMTP state machine: 1. Connect → receive 220 2. EHLO → 250 (extension negotiation) 3. [STARTTLS → EHLO again if upgrading] 4. MAIL FROM → 250 (start transaction, set sender) 5. RCPT TO → 250 (can repeat for multiple recipients) 6. DATA → 354 (start message body) 7. [message body] → 250 (message accepted) 8. [optional: RSET → back to step 4 for another message] 9. QUIT → 221
Common 503 triggers: RCPT TO before MAIL FROM: '503 5.5.0 Error: need MAIL command' DATA before RCPT TO: '503 5.5.0 Error: need RCPT command' MAIL FROM inside an open transaction: '503 5.5.0 Error: sender already specified' DATA with zero accepted recipients: all RCPT TOs bounced AUTH after MAIL FROM: AUTH must be done after EHLO but before MAIL FROM
Fix pattern: Send RSET to reset the transaction back to post-EHLO state. Then restart with MAIL FROM.
Enhanced status codes
| Code | Meaning |
|---|---|
| 503 5.5.0 | Other or undefined protocol status – command out of sequence |
When you'll see this
- →Buggy SMTP library skips EHLO and goes straight to MAIL FROM after connecting
- →Retry logic re-sends MAIL FROM after a failed RCPT TO without sending RSET first
- →AUTH command sent after MAIL FROM instead of after EHLO
- →Pipelining code sends commands in wrong order when server does not support pipelining
Edge cases
- !After 503, the session is still open – always send RSET to reset state before retrying
- !Some servers are lenient and silently reset state on MAIL FROM even mid-transaction; others strictly return 503
- !EHLO must be re-sent after STARTTLS – some clients forget this and proceed directly to MAIL FROM
Related codes
FAQ
How do I fix 503 in my SMTP code?
Send RSET to reset the transaction state, then restart from MAIL FROM. If you are getting 503 on the initial RCPT TO, ensure your code sent EHLO and MAIL FROM first. If you are getting 503 on MAIL FROM, you have an open transaction – send RSET before the new MAIL FROM.