Key points
- Port 25 carries mail between servers; ports 587 and 465 are for users submitting mail with authentication.
- A session follows the sequence EHLO, MAIL FROM, RCPT TO, DATA and QUIT.
- Replies starting with 2 mean success, 4 means try again later and 5 means permanent failure.
- The envelope addresses in MAIL FROM and RCPT TO can differ from the From and To headers.
- Reading the mailbox is done with IMAP or POP3, not with SMTP.
How does an SMTP session work?
The client connects and the server greets it with code 220. The client introduces itself with EHLO and the server lists its extensions, such as STARTTLS and AUTH. The client then sends MAIL FROM with the envelope sender, one RCPT TO per recipient and DATA followed by the message, which ends with a line containing only a dot.
The server accepts with 250 and queues the message. If it cannot accept, a 4xx code tells the sender to retry later and a 5xx code tells it to give up and return a bounce.
What is the difference between the SMTP ports?
Port 25 is for delivery between servers and is often blocked on residential connections. Port 587 is the submission port, where the user authenticates and usually upgrades with STARTTLS. Port 465 is submission with implicit TLS, recommended by RFC 8314.
Why is SMTP abused by spammers?
The original protocol trusted the sender's word. Anyone could claim any address in MAIL FROM, and open relays forwarded mail for anyone. Authentication on submission, SPF, DKIM and DMARC were added over the years to close those gaps.
Example SMTP session
S: 220 mx.example.com ESMTP
C: EHLO mail.example.com
S: 250-mx.example.com
S: 250 SIZE 52428800
C: MAIL FROM:<[email protected]>
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: Subject: Test
C:
C: Hello.
C: .
S: 250 2.0.0 Ok: queued
C: QUIT
S: 221 2.0.0 ByeHow AHSU 360 handles this
AHSU 360 receives the SMTP traffic of the domain before the mail server and filters spam and viruses in layers. For outgoing mail, the partner server sends through the UNODATA relay, which applies a limit per account and signs with DKIM.
