Networking
SMTP
An IoT gateway that emails an alert when a sensor crosses a threshold, or a web app that sends a password-reset link, is doing exactly one thing: handing a message to an SMTP server and trusting it to relay that message onward, hop by hop, until it reaches the recipient's mailbox.
- What it is
- The protocol for transferring email from a sender to a mail server, and between mail servers, toward a recipient.
- Mental model
- Physical postal relay — your letter moves from your local post office to the next, hop by hop, until it reaches the one that actually delivers to the recipient's address.
- Key numbers
- Port 25 for server-to-server relay; port 587 ("submission") for an authenticated client sending its own outbound mail.
- Reach for it when
- Any application or device that needs to send an outbound notification/alert email — never for reading a mailbox, which is a different protocol entirely.
SMTP only sends — a common mix-up
SMTP moves mail forward — from a client to its outgoing server, and from server to server toward the destination. It has no concept of "check my inbox." Retrieving mail from a mailbox is a completely separate pair of protocols, POP3 (downloads and typically removes messages from the server) or IMAP (keeps mail on the server, syncing state like read/unread across multiple devices) — an email client uses SMTP to send and one of those two to receive, and mixing the two up is a very common source of confusion.
The command sequence
A session is a short, readable sequence of plain-text commands:
- EHLO
- Client greets the server and announces itself (the modern form of the older
HELO). - MAIL FROM
- Declares the sender's address.
- RCPT TO
- Declares one recipient — sent once per recipient for a multi-recipient message.
- DATA
- Everything that follows, until a line with just a single period, is the message headers and body.
- QUIT
- Ends the session.
Relaying, hop by hop
A message often crosses more than one SMTP server before reaching its destination mailbox — each server along the way is only responsible for handing it to the next one, not for guaranteeing end-to-end delivery in the way TCP guarantees byte delivery. If a hop ultimately fails, the sender doesn't find out inline — a separate bounce message arrives later, asynchronously, itself sent back over SMTP.
Why port 587 exists alongside port 25
Port 25 was SMTP's original port, meant for server-to-server relay — and because that made it a favorite target for spam, most residential and many cloud ISPs now block outbound port 25 entirely for ordinary customers. Port 587 ("submission") exists specifically for a legitimate client authenticating and submitting its own outbound mail — it's expected to require a username/password and TLS, which is why an application sending alert emails almost always connects to port 587, not port 25.
Real-world applications
- IoT/monitoring alert emails — a device or backend service emailing "sensor X crossed threshold Y" is a direct SMTP submission, typically on port 587.
- Transactional email services — providers that handle account-notification, password-reset, and receipt emails on behalf of an application expose an SMTP relay (or an HTTP API that does the same job) so the application never has to run its own mail server.
- Server-to-server mail delivery — every email provider (Gmail, Outlook, and everything else) still ultimately exchanges messages with other providers over SMTP on port 25.
Gotchas
- An email that sends successfully but lands in spam is very often an SPF/DKIM/DMARC problem, not an SMTP one — these are DNS records that let a receiving server verify a message really came from who it claims to; a device or service sending alert emails from a domain without them configured is a common, easy-to-miss cause of "alerts stopped arriving."
- A misconfigured "open relay" — an SMTP server that accepts and forwards mail from anyone, not just its own authenticated users — is a classic historical spam vector; modern SMTP servers require authentication for submission specifically to prevent this.
- SMTP delivery is not instantaneous by design — queuing and retry delays at any hop are normal, not necessarily a sign something is broken.