How SMTP works (sending email)
SMTP is the protocol that moves email from sender to server to inbox. Here’s the actual conversation it has, and why mail you send sometimes never arrives.
What SMTP is
SMTP, the Simple Mail Transfer Protocol: is how email is sent and relayed between servers. It is a push protocol: a client hands a message to a server, which relays it toward the recipient’s mail server. (Getting mail back out of a mailbox is a different job, see POP3 vs IMAP.) SMTP normally runs on port 25 for server-to-server relay, and ports 587 or 465 for an authenticated client submitting outgoing mail.
The SMTP conversation
SMTP is a line-based, human-readable exchange of commands and numeric replies. A simplified send looks like:
HELO/EHLO: the client greets the server and discovers its capabilities.MAIL FROM:: declares the envelope sender (the return-path).RCPT TO:: declares each recipient; repeated once per address.DATA: everything after this is the message itself (headers, a blank line, then the body), terminated by a line containing only a dot.QUIT: ends the session.
The server answers each command with a status code: 2xx success, 4xx temporary failure (try again later), 5xx permanent rejection.
Envelope vs headers, the part that confuses everyone
The MAIL FROM/RCPT TO you send in the conversation are the envelope: that’s what actually routes the mail. The From: and To: lines inside
the DATA block are just headers the mail client displays. They don’t have to match the
envelope, which is exactly why email spoofing was easy for decades and why the anti-spoofing checks below exist.
Why your mail gets blocked
Deliverability now depends on three records that prove a message is legitimately from your domain:
- SPF: a DNS record listing which servers may send for your domain.
- DKIM: a cryptographic signature on the message, verified against a public key in DNS.
- DMARC: a policy that ties SPF/DKIM to the visible
From:domain and tells receivers what to do on failure.
Miss these and even genuine mail lands in spam or is rejected outright with a 5xx.
FAQ
Does SMTP receive mail too?
Servers receive over SMTP when relaying, but end users read mail with POP3 or IMAP. SMTP’s job is moving mail toward the destination, not serving a mailbox.
Why port 587 instead of 25?
Port 25 is for server-to-server relay and is widely blocked for clients to curb spam. Authenticated submission from an app or mail client uses 587 (STARTTLS) or 465 (implicit TLS).
What’s a 4xx vs 5xx reply?
4xx is temporary, the sender should retry later. 5xx is permanent, the message is rejected and won’t be retried.
Related
Reading mail uses POP3 or IMAP. SMTP rides on TCP like HTTP; encode attachments with Base64.