Web and appsApplicationRFC 5321
SMTP: sending an email
The short text conversation mail servers use to hand over an email.
Ports and use: TCP 25 (server to server), 587 (from your mail app)
In one sentenceSMTP is a polite back and forth: say hello, name the sender and receiver, send the message, say goodbye.
Think of it like thisIt is a courier at a reception desk: "I have a parcel from Asha for Ravi" - "Go ahead" - "Here it is" - "Received".
Watch it happen
11 steps and 11 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.
- Sending server
- Receiving server
- 220 greetingReceiving server to Sending server
- EHLOSending server to Receiving server
- 250 capabilitiesReceiving server to Sending server
- MAIL FROMSending server to Receiving server
- 250 OKReceiving server to Sending server
- RCPT TOSending server to Receiving server
- 250 OKReceiving server to Sending server
- DATASending server to Receiving server
- 354 go aheadReceiving server to Sending server
- The messageSending server to Receiving server
- 250 queued, then QUITReceiving server to Sending server
Step 1 of 11 220 greeting
Receiving server → Sending server
After the TCP connection opens, the receiving server speaks first and says it is ready.
Server greeting 34 bytes
220 mail.example.com ESMTP ready↵
| Field | Text | What it means |
|---|---|---|
| Greeting | 220 mail.example.com ESMTP ready↵ | 220 means "ready". It names the server and the protocol. |
Step 2 of 11 EHLO
Sending server → Receiving server
The sender introduces itself. EHLO asks the server to list its extra features.
Client hello 25 bytes
EHLO laptop.example.org↵
| Field | Text | What it means |
|---|---|---|
| Command | EHLO laptop.example.org↵ | EHLO followed by the sender's name. |
Step 3 of 11 250 capabilities
Receiving server → Sending server
The server replies with a list. Lines that start with 250 and a dash mean "more lines follow".
Server features 95 bytes
250-mail.example.com greets laptop.example.org↵ 250-SIZE 35882577↵ 250-STARTTLS↵ 250 8BITMIME↵
| Field | Text | What it means |
|---|---|---|
| Line 1 | 250-mail.example.com greets laptop.example.org↵ | The first line names both sides. |
| Line 2 | 250-SIZE 35882577↵ | Largest message accepted, in bytes. |
| Line 3 | 250-STARTTLS↵ | The server can switch to an encrypted connection. Modern senders use it before going on. |
| Line 4 | 250 8BITMIME↵ | The final line uses 250 and a space. |
Step 4 of 11 MAIL FROM
Sending server → Receiving server
The sender names the return address, called the envelope sender.
Sender 30 bytes
MAIL FROM:<[email protected]>↵
| Field | Text | What it means |
|---|---|---|
| Command | MAIL FROM:<[email protected]>↵ | Who is sending, and where to return errors. |
Step 5 of 11 250 OK
Receiving server → Sending server
The server accepts the sender.
Reply 21 bytes
250 2.1.0 Sender OK↵
| Field | Text | What it means |
|---|---|---|
| Reply | 250 2.1.0 Sender OK↵ | A 250 reply means success. The 2.1.0 is a more detailed status. |
Step 6 of 11 RCPT TO
Sending server → Receiving server
The sender names who the message is for. This can repeat for each recipient.
Recipient 28 bytes
RCPT TO:<[email protected]>↵
| Field | Text | What it means |
|---|---|---|
| Command | RCPT TO:<[email protected]>↵ | Where to deliver the message. |
Step 7 of 11 250 OK
Receiving server → Sending server
The server agrees to accept mail for that address.
Reply 24 bytes
250 2.1.5 Recipient OK↵
| Field | Text | What it means |
|---|---|---|
| Reply | 250 2.1.5 Recipient OK↵ | The server will take this message. |
Step 8 of 11 DATA
Sending server → Receiving server
The sender says it is ready to send the actual message.
Command 6 bytes
DATA↵
| Field | Text | What it means |
|---|---|---|
| Command | DATA↵ | The message follows. |
Step 9 of 11 354 go ahead
Receiving server → Sending server
The server says to send the message and finish with a line containing only a full stop.
Reply 46 bytes
354 Start mail input; end with <CRLF>.<CRLF>↵
| Field | Text | What it means |
|---|---|---|
| Reply | 354 Start mail input; end with <CRLF>.<CRLF>↵ | 354 means "continue". |
Step 10 of 11 The message
Sending server → Receiving server
Headers, a blank line, the body, and a single full stop on its own line to mark the end.
Message 96 bytes
From: Asha <[email protected]>↵ To: Ravi <[email protected]>↵ Subject: Hello↵ ↵ See you at 5.↵ .↵
| Field | Text | What it means |
|---|---|---|
| Header: From | From: Asha <[email protected]>↵ | The name shown to the reader. It can differ from the envelope sender, which is why spoofing is possible. |
| Header: To | To: Ravi <[email protected]>↵ | The names shown to the reader. |
| Header: Subject | Subject: Hello↵ | The subject line. |
| Blank line | ↵ | Separates the headers from the body. |
| Body | See you at 5.↵ | The text of the email. |
| End marker | .↵ | A line with a single full stop ends the message. |
Step 11 of 11 250 queued, then QUIT
Receiving server → Sending server
The server accepts responsibility for delivery. The sender then sends QUIT and the server answers 221 and closes.
Reply 28 bytes
250 2.0.0 Queued as 4F2A91↵
| Field | Text | What it means |
|---|---|---|
| Reply | 250 2.0.0 Queued as 4F2A91↵ | The server has stored the message and gave it an ID you can use to trace it. |
Where you meet it
- Every outgoing email from apps, websites and mail programs.
- Password reset and notification emails sent by services.
- Mail passing between servers on its way to your inbox.
Common mistakes
- Assuming the From header proves who sent the mail. Use SPF, DKIM and DMARC to check.
- Sending over port 25 from a home network, which many providers block.
- Skipping STARTTLS, so mail travels as readable text.
- Treating a 250 reply as "delivered". It only means "accepted for delivery".
Try it yourself
Run these on your own computer and compare the output with the lesson above.
openssl s_client -starttls smtp -connect smtp.example.com:587Opens an encrypted SMTP session you can type commands into. Replace the host with a server you are allowed to test.dig example.com MX +shortShows which servers receive mail for a domain.
Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.