All guides
Term

SMTP

An application layer protocol used for sending and relaying email messages between clients and servers or between mail servers.

SMTP (Simple Mail Transfer Protocol) is an application layer protocol used for sending and relaying email messages between clients and servers or between mail servers over TCP/IP networks. Unlike retrieval protocols such as IMAP or POP3, which pull messages into an inbox, SMTP is strictly a push protocol responsible for routing and delivering outbound mail.

How it works

An SMTP transaction operates as a stateful, text-based conversation over a TCP connection between a Mail User Agent (MUA) or sending server and a Mail Transfer Agent (MTA) like Postfix or Exim. Extended SMTP (ESMTP) adds modern capabilities such as authentication and encryption to the baseline command set.

  1. Handshake: The client initiates the connection and introduces itself using EHLO (or legacy HELO). The server responds with a 250 status code and lists supported extensions.
  2. Security and authentication: On submission ports, the client upgrades the plain-text connection to TLS using STARTTLS and verifies credentials via AUTH.
  3. Envelope routing: The sender specifies the bounce address with MAIL FROM and one or more destination addresses with RCPT TO.
  4. Payload transfer: After sending the DATA command, the client transmits the message headers and body, ending with a single period (.) on its own line.
  5. Termination: The server queues the message for local delivery or further relay, returns a final 250 acknowledgment, and closes the session upon receiving QUIT.

To prevent spam and spoofing, modern deployments separate traffic across specific ports: port 25 is reserved for unauthenticated server-to-server relay, while ports 587 (STARTTLS) and 465 (implicit TLS) handle authenticated client submission.

Example

The following raw session demonstrates a basic SMTP submission exchange using STARTTLS and AUTH LOGIN before transmitting a message payload:

S: 220 mail.example.com ESMTP Postfix
C: EHLO app.example.com
S: 250-mail.example.com
S: 250-STARTTLS
S: 250 AUTH PLAIN LOGIN
C: STARTTLS
S: 220 2.0.0 Ready to start TLS
[TLS negotiation completes]
C: EHLO app.example.com
S: 250-mail.example.com
S: 250 AUTH PLAIN LOGIN
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6
C: dXNlckBleGFtcGxlLmNvbQ==
S: 334 UGFzc3dvcmQ6
C: c2VjcmV0cGFzc3dvcmQ=
S: 235 2.7.0 Authentication successful
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: Server Alert
C: From: [email protected]
C: To: [email protected]
C:
C: Disk usage exceeded threshold.
C: .
S: 250 2.0.0 Ok: queued as 8F4A21C09
C: QUIT
S: 221 2.0.0 Bye

What matters when choosing a server or hosting

Running outbound mail requires infrastructure-level permissions and clean network reputation that standard web hosting rarely provides out of the box.

  • Unblocked outbound port 25: Most cloud providers block outbound port 25 by default to curb spam. You must either request a port lift or route traffic through an external smarthost, as covered in our Postfix SMTP Relay Setup: Guide for High Deliverability.
  • Reverse DNS (PTR records): Receiving MTAs reject connections when the sending IP address does not resolve back to a matching hostname.
  • Dedicated IP reputation: Shared VPS IP blocks often suffer from noisy neighbors. High-volume senders should evaluate dedicated IP warming versus managed relays—see our Cheap SMTP Relay: Deliverability Data and Price Comparison for trade-offs.
  • Queue management and throughput: Self-managed instances need sufficient disk I/O and tuning to handle retry queues during temporary deferrals (4xx responses), especially if you self-host SMTP for newsletters.

Common mistakes

  • Configuring applications to send over port 25: Application containers and web apps should connect via port 587 or 465 with authentication rather than using unencrypted server-to-server relay ports.
  • Omitting SPF, DKIM, and DMARC records: SMTP itself does not verify sender identity. Without DNS authentication records, major mailbox providers will quarantine or reject valid messages.
  • Creating an open relay: Misconfigured ACLs that allow unauthenticated third parties to relay mail through your server will rapidly land your IP on global blocklists.
  • Mismatched EHLO and PTR hostnames: Advertising an internal hostname like localhost.localdomain during the EHLO handshake triggers spam filters at strict receiving servers.

FAQ

What is the difference between SMTP, IMAP, and POP3?

SMTP handles sending and relaying messages between servers, whereas IMAP and POP3 are retrieval protocols used by email clients to download or synchronize messages from a mail server.

Should I use port 465 or port 587 for client submission?

Both are valid for authenticated submission. Port 465 initiates implicit TLS immediately upon connection, while port 587 starts in plain text and upgrades via STARTTLS; port 465 is slightly faster and avoids downgrade attacks if STARTTLS is not strictly enforced.

Why do SMTP servers return 4xx versus 5xx error codes?

A 4xx code indicates a temporary failure (such as greylisting or a full mailbox), instructing the sending MTA to keep the message in its queue and retry later. A 5xx code signals a permanent failure (such as a nonexistent user or policy rejection), prompting an immediate bounce.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.