networking, updated

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)
Specs
RFC 5321, RFC 5322, RFC 3207, RFC 4954, RFC 8314
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
CommandPurpose
EHLO / HELOIntroduce the client; EHLO returns the supported extensions
STARTTLSUpgrade the connection to TLS
AUTHLog in (submission ports); PLAIN and LOGIN are only Base64
MAIL FROMEnvelope sender (return path, checked by SPF)
RCPT TOEnvelope recipient, once per recipient
DATAMessage (headers + body), ended by a line with a single .
VRFY / EXPNCheck a user / expand a list (should be disabled)
RSET, NOOP, QUITReset, keep-alive, end
ReplyMeaning
2xxSuccess (220 ready, 250 OK, 235 authenticated)
3xxSend more (334 auth challenge, 354 start mail input)
4xxTemporary failure, retry later (421, 450 mailbox busy, greylisting)
5xxPermanent failure (530 auth required, 535 auth failed, 550 rejected / no such user, 554)

How it works

  1. The mail client submits the message to its provider on 587 (STARTTLS) or 465 (TLS) with AUTH.
  2. The provider looks up the recipient domain’s MX record in DNS and relays the message to that server on port 25.
  3. 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

FilterShows
smtpSMTP commands and replies
smtp.req.command == "AUTH"Logins (Base64 credentials if not encrypted)
smtp.req.command == "STARTTLS"Encryption upgrades
smtp.response.code >= 500Rejections
smtp.req.parameter contains "FROM"Envelope senders
imfThe mail itself (Internet Message Format: headers, body)
tcp.port == 25 && tlsServer-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

References

§ home
~/knubertus/home/
1,1 Top