====== SMTP (Simple Mail Transfer Protocol) ======
**SMTP (Simple Mail Transfer Protocol)** is the standard protocol used to **send email** over the Internet.
Whenever you send an email, your email client communicates with an SMTP server, which then delivers the message to the recipient's mail server.
SMTP is used only for **sending** email. Receiving email is typically handled by **IMAP** or **POP3**.
-----
===== How SMTP Works =====
When you send an email, the following steps occur:
- Your email client connects to an SMTP server.
- The SMTP server authenticates the sender (if required).
- The server looks up the recipient domain's **MX record**.
- The sending server connects to the recipient's SMTP server.
- The recipient's server accepts and stores the message.
Your Email Client
│
▼
SMTP Server
│
▼
DNS MX Lookup
│
▼
Recipient SMTP Server
│
▼
Recipient Mailbox
-----
===== SMTP Commands =====
SMTP is a text-based protocol.
Typical conversation:
HELO example.com
MAIL FROM:
RCPT TO:
DATA
(message contents)
QUIT
Modern SMTP servers usually use **EHLO** instead of **HELO** because it supports additional features.
-----
===== Common SMTP Ports =====
^ Port ^ Purpose ^
| 25 | Server-to-server email transfer |
| 587 | Message submission (recommended for clients) |
| 465 | SMTP over SSL/TLS (SMTPS) |
Today, email clients should normally use **587** with STARTTLS or **465** with implicit TLS.
-----
===== SMTP Authentication =====
Most SMTP servers require authentication before allowing users to send email.
Typical credentials:
* Username (usually the email address)
* Password
Without authentication, the server may refuse to relay messages.
-----
===== SMTP Security =====
Modern SMTP uses encryption to protect credentials and message transmission.
Two common methods are:
* **STARTTLS** (usually on port 587)
* **Implicit TLS** (usually on port 465)
Encryption helps protect against eavesdropping while data travels across the network.
-----
===== SMTP Relay =====
An SMTP server that forwards email to another server is performing **mail relay**.
Example:
alice@example.com
↓
mail.example.com
↓
mail.example.net
↓
bob@example.net
Open relays (servers that allow anyone to relay email) are considered a major security risk and are almost always blocked.
-----
===== SMTP and DNS =====
SMTP relies heavily on DNS.
Before delivering an email, the sending server performs an **MX lookup** to determine which server accepts email for the recipient's domain.
Example:
example.net
↓
MX Record
↓
mail.example.net
If no valid MX record exists, delivery may fail.
-----
===== SMTP Response Codes =====
SMTP servers return numeric status codes.
Common examples:
^ Code ^ Meaning ^
| 220 | Service ready |
| 221 | Service closing |
| 235 | Authentication successful |
| 250 | Requested action completed |
| 421 | Service unavailable |
| 450 | Mailbox unavailable (temporary) |
| 451 | Local processing error |
| 452 | Insufficient storage |
| 550 | Mailbox unavailable or rejected |
| 551 | User not local |
| 552 | Mailbox full |
| 553 | Invalid mailbox |
| 554 | Transaction failed |
Codes beginning with:
* **2xx** → Success
* **4xx** → Temporary failure
* **5xx** → Permanent failure
-----
===== SMTP vs IMAP vs POP3 =====
These protocols have different purposes.
^ Protocol ^ Purpose ^
| SMTP | Send email |
| IMAP | Read and synchronize email |
| POP3 | Download email |
SMTP sends messages, while IMAP and POP3 retrieve them.
-----
===== SMTP and Telenegar =====
The **Telenegar Mail Check** service can help diagnose SMTP-related problems such as:
* Incorrect MX configuration
* SMTP connectivity
* TLS availability
* Reverse DNS issues
* SPF, DKIM and DMARC configuration
* Common delivery problems
These checks help improve email deliverability.
-----
===== Common Misconceptions =====
* **SMTP receives email.**
* False. SMTP sends email.
* **Port 25 should be used by email clients.**
* Generally false. Email clients should normally use port 587 or 465.
* **SMTP encrypts email by default.**
* False. Encryption is provided by TLS.
-----
===== Best Practices =====
* Use port **587** with STARTTLS whenever possible.
* Enable SMTP authentication.
* Configure SPF, DKIM and DMARC.
* Ensure your server has valid reverse DNS (PTR).
* Use a valid TLS certificate.
-----
===== Related Topics =====
* [[email:mx-records|MX Records]]
* [[email:imap|IMAP]]
* [[email:pop3|POP3]]
* [[email:spf|SPF]]
* [[email:dkim|DKIM]]
* [[email:dmarc|DMARC]]
* [[networking:dns:dns|DNS Explained]]
* [[tools:mailcheck|Mail Check]]
-----
{{tag>email smtp mail tls dns mx authentication}}