SMTP
The Simple Mail Transfer Protocol moves email from clients to servers and between servers. A text protocol from 1982 with authentication and encryption added later, which is why spoofing and phishing still work.
- OSI layer
- 7 Application
- Carried in
- TCP
- Ports
- 25/tcp (server to server), 587/tcp (submission, STARTTLS), 465/tcp (submission, implicit TLS)
- Wireshark filter
smtp || imf- Encrypted
- no
Packet structure
SMTP has no binary header: client and server exchange lines of text (ending in \r\n) over TCP. The client sends commands, the server answers with a 3-digit reply code and text:
S: 220 mx.example.com ESMTP ready
C: EHLO client.example.org
S: 250-mx.example.com
S: 250-SIZE 52428800
S: 250-STARTTLS
S: 250 AUTH PLAIN LOGIN
C: STARTTLS
S: 220 Ready to start TLS
... TLS handshake, then EHLO again ...
C: MAIL FROM:<alice@example.org>
S: 250 OK
C: RCPT TO:<bob@example.com>
S: 250 OK
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Alice <alice@example.org>
C: To: Bob <bob@example.com>
C: Subject: Hello
C:
C: Hi Bob!
C: .
S: 250 OK queued as 4F2A1C
C: QUIT
S: 221 Bye
| Command | Purpose |
|---|---|
EHLO / HELO | Introduce the client; EHLO returns the supported extensions |
STARTTLS | Upgrade the connection to TLS |
AUTH | Log in (submission ports); PLAIN and LOGIN are only Base64 |
MAIL FROM | Envelope sender (return path, checked by SPF) |
RCPT TO | Envelope recipient, once per recipient |
DATA | Message (headers + body), ended by a line with a single . |
VRFY / EXPN | Check a user / expand a list (should be disabled) |
RSET, NOOP, QUIT | Reset, keep-alive, end |
| Reply | Meaning |
|---|---|
| 2xx | Success (220 ready, 250 OK, 235 authenticated) |
| 3xx | Send more (334 auth challenge, 354 start mail input) |
| 4xx | Temporary failure, retry later (421, 450 mailbox busy, greylisting) |
| 5xx | Permanent failure (530 auth required, 535 auth failed, 550 rejected / no such user, 554) |
How it works
- The mail client submits the message to its provider on 587 (STARTTLS) or 465 (TLS) with AUTH.
- The provider looks up the recipient domain’s MX record in DNS and relays the message to that server on port 25.
- The receiving server checks SPF, DKIM and DMARC, spam and malware, then stores the message. The recipient fetches it with IMAP or POP3 (or webmail).
The envelope (MAIL FROM, RCPT TO) and the header (From:, To:) are separate: the user sees the header, delivery uses the envelope. Spoofing lives in that gap.
In Wireshark
| Filter | Shows |
|---|---|
smtp | SMTP commands and replies |
smtp.req.command == "AUTH" | Logins (Base64 credentials if not encrypted) |
smtp.req.command == "STARTTLS" | Encryption upgrades |
smtp.response.code >= 500 | Rejections |
smtp.req.parameter contains "FROM" | Envelope senders |
imf | The mail itself (Internet Message Format: headers, body) |
tcp.port == 25 && tls | Server-to-server traffic after STARTTLS |
File › Export Objects › IMF saves complete messages as .eml.
What normal looks like: clients only talk to your mail server on 587/465; only the mail gateway talks port 25 to the internet. A workstation connecting to external hosts on port 25 is often malware sending spam.
Security notes
- Spoofing: SMTP itself does not check the sender. SPF (allowed sending IPs), DKIM (signature) and DMARC (policy + alignment with
From:) do, if the domain publishes them and the receiver enforces them. - Open relay: a server that accepts mail from anyone for anyone gets abused for spam. Test with
RCPT TOan outside domain without AUTH. - User enumeration:
VRFY,EXPNand different replies toRCPT TOfor valid and invalid users (smtp-user-enum). - STARTTLS stripping: an on-path attacker removes
STARTTLSfrom the EHLO reply and the session stays clear text. MTA-STS and DANE enforce TLS between servers; implicit TLS (465) avoids it for submission. - Credential theft: AUTH PLAIN/LOGIN is Base64, readable in any unencrypted capture.
- Phishing and malware delivery: most attacks still start as an email; headers (
Received:,Authentication-Results:) show the real path. - SMTP smuggling (2023): different end-of-data interpretations let attackers inject a second spoofed message.
Versions and related
- ESMTP: the extensions announced after EHLO (STARTTLS, AUTH, SIZE, PIPELINING, 8BITMIME, SMTPUTF8).
- IMAP (143/993) and POP3 (110/995) fetch mail; SMTP only sends.
- TLS via STARTTLS or implicit TLS; DNS holds MX, SPF, DKIM and DMARC records.