Understanding SMTP: The Protocol Behind Email Delivery
Alex Chen
December 20, 2025
A deep dive into the Simple Mail Transfer Protocol (SMTP) and how it powers email communication across the internet.
Introduction
Simple Mail Transfer Protocol (SMTP) is the foundation of email communication on the internet. Developed in the early 1980s, SMTP remains the standard protocol for sending emails between servers. Understanding how SMTP works is essential for anyone interested in email technology, security, or building email-related applications.
Email Delivery Overview
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Sender │ │ Sender's │ │ Recipient's │ │ Recipient │
│ (You/App) │ │ SMTP Server │ │ SMTP Server │ │ Mailbox │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │ │
│ 1. Compose │ │ │
│ & Send │ │ │
│──────────────────>│ │ │
│ │ │ │
│ │ 2. DNS Lookup │ │
│ │ (Find MX record) │ │
│ │──────────────────>│ │
│ │ │ │
│ │ 3. SMTP Session │ │
│ │ (Deliver email) │ │
│ │──────────────────>│ │
│ │ │ │
│ │ │ 4. Store in │
│ │ │ mailbox │
│ │ │──────────────────>│
│ │ │ │How SMTP Works
SMTP operates on a client-server model. When you send an email, your email client connects to an SMTP server, which then relays the message to the recipient's mail server. The process involves several steps:
1. Connection Establishment
The sending mail server (or client) establishes a TCP connection to the receiving SMTP server, typically on port 25, 587, or 465. The server responds with a greeting message indicating it's ready to receive commands.
2. SMTP Handshake
The client introduces itself using the EHLO (Extended Hello) or HELO command:
EHLO mail.sender.comThe server responds with its capabilities, including supported extensions like authentication methods and encryption options.
3. Sender and Recipient Specification
The client specifies the sender using the MAIL FROM command and recipients using RCPT TO:
MAIL FROM:<sender@example.com>
RCPT TO:<recipient@example.com>4. Data Transfer
The actual email content is sent using the DATA command. The message includes headers (From, To, Subject, Date) and the body, terminated by a single period on a line by itself:
DATA
From: sender@example.com
To: recipient@example.com
Subject: Hello World
This is the email body.
.5. Connection Termination
The session ends with the QUIT command.
Complete SMTP Conversation Example
┌──────────────────┐ ┌──────────────────┐
│ SMTP Client │ │ SMTP Server │
│ (Sending Mail) │ │ (Receiving Mail) │
└────────┬─────────┘ └────────┬─────────┘
│ │
│ TCP Connect (port 25) │
│──────────────────────────────────────────>│
│ │
│ 220 mail.example.com ESMTP ready │
│<──────────────────────────────────────────│
│ │
│ EHLO sender.com │
│──────────────────────────────────────────>│
│ │
│ 250-mail.example.com Hello │
│ 250-SIZE 35882577 │
│ 250-STARTTLS │
│ 250 OK │
│<──────────────────────────────────────────│
│ │
│ MAIL FROM:<user@sender.com> │
│──────────────────────────────────────────>│
│ │
│ 250 OK │
│<──────────────────────────────────────────│
│ │
│ RCPT TO:<user@example.com> │
│──────────────────────────────────────────>│
│ │
│ 250 OK │
│<──────────────────────────────────────────│
│ │
│ DATA │
│──────────────────────────────────────────>│
│ │
│ 354 Start mail input │
│<──────────────────────────────────────────│
│ │
│ From: user@sender.com │
│ To: user@example.com │
│ Subject: Hello │
│ [blank line] │
│ Message body... │
│ . │
│──────────────────────────────────────────>│
│ │
│ 250 OK: Message queued │
│<──────────────────────────────────────────│
│ │
│ QUIT │
│──────────────────────────────────────────>│
│ │
│ 221 Bye │
│<──────────────────────────────────────────│
│ │SMTP Security Extensions
Modern SMTP implementations include several security enhancements:
STARTTLS
STARTTLS upgrades a plain text connection to an encrypted TLS connection. This prevents eavesdropping and man-in-the-middle attacks.
SMTP Authentication (SMTP AUTH)
Before sending emails, users must authenticate using mechanisms like PLAIN, LOGIN, or more secure options like CRAM-MD5 or OAuth 2.0.
SPF, DKIM, and DMARC
These email authentication protocols help prevent spoofing and phishing:
Common SMTP Response Codes
| Code | Meaning |
|---|---|
| 250 | Requested action completed successfully |
| 354 | Start mail input (after DATA command) |
| 421 | Service not available, closing connection |
| 450 | Mailbox unavailable (temporary) |
| 550 | Mailbox unavailable (permanent) |
| 553 | Mailbox name not allowed |
Conclusion
SMTP has evolved significantly since its inception, incorporating security features while maintaining backward compatibility. Understanding this protocol is crucial for anyone working with email systems, from developers building email applications to administrators managing mail servers.