Behind every email library call is a short text conversation between two computers. A client connects to a server and the two exchange lines: greetings, capabilities, credentials, sender, recipients and finally the message itself. Each line from the server begins with a three-digit code that says what happened. Once you can read this conversation, error messages stop being mysterious: you can see which step failed, what the server wanted instead and what to change. This guide walks through a complete, annotated SMTP session, shows variations for the most common failures and explains how to capture a transcript of your own. It complements testing SMTP connections, HELO and EHLO errors and SMTP extensions.
A complete successful session
S: 220 smtp.example.com ESMTP ready
C: EHLO app1.example.net
S: 250-smtp.example.com
S: 250-SIZE 52428800
S: 250-PIPELINING
S: 250-8BITMIME
S: 250-STARTTLS
S: 250 ENHANCEDSTATUSCODES
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
(TLS handshake happens here)
C: EHLO app1.example.net
S: 250-smtp.example.com
S: 250-AUTH PLAIN LOGIN
S: 250 SIZE 52428800
C: AUTH PLAIN AHVzZXIAcGFzc3dvcmQ=
S: 235 2.7.0 Authentication successful
C: MAIL FROM:<[email protected]> SIZE=1842
S: 250 2.1.0 Ok
C: RCPT TO:<[email protected]>
S: 250 2.1.5 Ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Example <[email protected]>
C: To: [email protected]
C: Subject: Hello
C: Message-ID: <[email protected]>
C: Date: Mon, 20 Mar 2025 10:00:00 +0000
C:
C: Hi Alice, this is a test.
C: .
S: 250 2.0.0 Ok: queued as 4F1A2C0B7E
C: QUIT
S: 221 2.0.0 ByeLines marked S come from the server, C from the client. The password in this example is only a Base64 placeholder; real credentials should never be pasted into tickets or logs.
Step by step
| Step | What happens | What to look for |
|---|---|---|
| 1. Connect and banner | The client opens TCP to port 25, 587 or 465. The server speaks first with 220 and its name | No banner means a firewall, a wrong port or an overloaded server. With port 465 the TLS handshake comes before the banner. See ports |
| 2. EHLO | The client names itself and asks for extensions. The server lists capabilities, one per line, with a hyphen on every line but the last | A 5xx reply to EHLO means the name was rejected; old servers may need HELO. The list shows STARTTLS, AUTH, SIZE and others |
| 3. STARTTLS | The client upgrades the connection to TLS. The server answers 220, then the handshake runs | Certificate or protocol failures appear here. See certificates |
| 4. EHLO again | After TLS the session state is reset, so the client must repeat EHLO | Capabilities such as AUTH often appear only after TLS |
| 5. AUTH | The client proves its identity (PLAIN, LOGIN or a stronger mechanism). 235 means success | 535 means wrong credentials. 530 means authentication or STARTTLS is required first. See 535 errors |
| 6. MAIL FROM | Declares the envelope sender and optionally the size | Policy rejections often happen here. See envelope From |
| 7. RCPT TO | One command per recipient; each gets its own reply | 550 means unknown or refused recipient; 452 means too many recipients; relay denied means the client is not allowed |
| 8. DATA | The server answers 354; the client then sends headers, a blank line, the body and a lone dot on a line | Anything starting with a dot is escaped by doubling it. Size limits and content filters respond after the final dot |
| 9. Final reply | 250 means the server accepted responsibility for delivery and usually shows a queue ID | Rejections here (for example 554 or 550 with a policy text) concern content, authentication or reputation |
| 10. QUIT | The client ends politely; the server answers 221 and closes | Skipping QUIT is harmless but untidy |
Reading reply codes
| Code | Meaning | Typical next move |
|---|---|---|
| 220 | Service ready / ready to start TLS | Continue |
| 221 | Closing connection | Done |
| 235 | Authentication successful | Continue |
| 250 | Requested action completed | Continue |
| 334 | Server wants more authentication data (Base64 challenge) | Send the response |
| 354 | Start sending the message | Send DATA content |
| 421 | Service not available; closing channel (often rate limiting) | Retry later. See 421 |
| 450, 451, 452 | Temporary mailbox, local error or storage problem | Retry. See retry schedules |
| 500, 501, 503 | Syntax error or bad command sequence | Fix the client command order. See 501 and 503 |
| 530, 535 | Authentication required or failed | Check STARTTLS and credentials |
| 550, 553, 554 | Permanent refusal: mailbox, address or policy | Read the text and enhanced code. See bounce classification |
Failure variations
# Authentication needed first
C: MAIL FROM:<[email protected]>
S: 530 5.7.0 Authentication required
# Wrong command order
C: RCPT TO:<[email protected]>
S: 503 5.5.1 Error: need MAIL command
# Relay not permitted
C: RCPT TO:<[email protected]>
S: 554 5.7.1 <[email protected]>: Relay access denied
# Unknown recipient
C: RCPT TO:<[email protected]>
S: 550 5.1.1 <[email protected]>: Recipient address rejected: User unknown
# Rate limited
S: 421 4.7.0 Too many connections from your IP, try again later
# Message refused after DATA
C: .
S: 550 5.7.26 Unauthenticated email is not accepted from this domainCapturing your own transcript
- Swaks prints the whole conversation by default:
swaks --to [email protected] --from [email protected] --server smtp.example.com:587 --tls --auth PLAIN --auth-user USER(it prompts for the password). - openssl s_client gives you a raw terminal:
openssl s_client -starttls smtp -connect smtp.example.com:587, then type commands yourself. Use-connect host:465without-starttlsfor implicit TLS. - Application debug logs. Most libraries have a debug mode (for example the debug level of Python smtplib or the debug property of Java Mail) that prints the dialogue. Redact credentials before sharing.
- Server logs. The receiving server records its own view of the session. See reading mail logs.
- Packet capture is a last resort and only useful before encryption starts; after STARTTLS the content is protected.
Pipelining, batching and multiple recipients
When the server advertises PIPELINING, a client may send several commands, such as MAIL FROM and many RCPT TO lines, without waiting for each reply, and then read the replies in order. This saves round trips on long-distance links and is why a transcript from a busy client may look different from the polite one-command-one-reply example above. The meaning is unchanged: every command still receives its own reply, and a rejected recipient does not stop the others from being accepted. A message to ten recipients can therefore end with nine acceptances and one 550, and the client must decide what to do with the rejected address, usually by recording a bounce for that recipient only. Servers also limit the number of recipients per message and per connection; a 452 on the hundredth RCPT TO is a signal to start another transaction on the same connection with the remaining recipients, after RSET or after the end of the current message.
Implicit TLS and submission variants
On port 465 the TLS handshake happens immediately after the TCP connection, before the server sends its banner, so there is no STARTTLS step, and the first line you see after the handshake is the 220 greeting. On port 587 the session starts in plain text and upgrades with STARTTLS, which is why a client that forgets to upgrade is told to issue STARTTLS first. Port 25 is for server-to-server delivery; many networks block it for end users, and authentication on it is rarely offered. Knowing which variant you are speaking helps you read the transcript: if the first thing you see is binary garbage or a hang, you probably spoke plain text to a port that expects TLS, or the reverse.
Common beginner problems visible in a transcript
- Sending MAIL FROM before authenticating or before STARTTLS, producing 530 or 503.
- Forgetting the second EHLO after STARTTLS, so the server ignores later commands or hides AUTH.
- Using LF instead of CR LF line endings in raw sessions or in message bodies, which some servers reject.
- Lines longer than 998 characters in headers or body, which servers may refuse or wrap.
- No Date or Message-ID header, triggering filter points. See the Date header.
- Messages above the advertised SIZE limit, answered with 552 after or before DATA.
- Opening many connections at once, which provokes 421 replies. Reuse connections instead. See connection pooling.
The SMTP dialogue is old, simple and remarkably readable. Learn the ten steps and the families of reply codes, capture a transcript whenever something fails and you will usually spot the cause in seconds: the step that did not get its expected code.
Test your SMTP connection Use a relay with clear logs and standard ports.
References and further reading
Frequently asked questions
What is the order of SMTP commands?
Connect, EHLO, optional STARTTLS and a second EHLO, AUTH if needed, MAIL FROM, RCPT TO, DATA, the message ending with a dot line, then QUIT.
What does reply code 250 mean?
The requested action succeeded. After DATA it means the server accepted the message for delivery.
Why must EHLO be repeated after STARTTLS?
TLS resets the session state, so the client must announce itself again and learn the new capabilities.
What does 354 mean?
The server is ready for the message content, which ends with a line containing only a dot.
How can I see a real SMTP transcript?
Use swaks, openssl s_client, or the debug mode of your mail library, and redact credentials before sharing.