TodayTools

Simple Mail Transfer Protocol

How SMTP works

Sends email from server to server

Donate
L7ApplicationPort 25, 587TCP
What brings you here?

Watch it happen

How much detail

Ravi sends Daniel an email: his phone hands it to his provider, which finds Daniel's mail server and passes it on.

Ravi's phone
Home router
Internet
DNS resolver
smtp.example.com
mx.example.net
Wi-FiInternetSetupResponseRequestDataLookupCloseEncrypted

6 steps, 29 packets

First up: Connect on 587. Press Play to watch it happen, one step at a time.

0 of 60/6

What is SMTP?

SMTP is how email moves. Your mail app hands a new message to your provider's server, and that server looks up the receiver's mail server in DNS and passes the message on. Each step is a short text conversation: hello, who from, who to, here is the message, okay.

SMTP only sends. Reading your inbox is a different job done by IMAP or POP3. Because plain SMTP never checked who the sender really was, three DNS-based checks were added on top: SPF, DKIM and DMARC. They are why fake mail from your bank usually lands in spam or is refused.

Think of it like this. SMTP is like the postal system. You drop a letter at your local post office (submission), which reads the city on the envelope (the domain after the @) and sends it to the post office there (relay). The address on the envelope and the name on the letter inside can differ, which is why fraud checks matter.

Step by step

Normal

6 steps

Ravi sends Daniel an email: his phone hands it to his provider, which finds Daniel's mail server and passes it on.

  1. 1

    Connect on 587

    Phone to Ravi's provider

    Mail apps do not send mail straight to the receiver. They hand it to their own provider on the submission port, 587. The server greets first with 220, and EHLO asks what it supports.

  2. 2

    STARTTLS

    Lock the connection

    STARTTLS turns the plain connection into an encrypted one. After this, someone on the same Wi-Fi sees only scrambled bytes.

  3. 3

    Log in and hand over

    AUTH, MAIL FROM, RCPT TO, DATA

    The phone proves who Ravi is with AUTH, then names the sender, the recipient and sends the message. The server replies 250 Ok and the phone's job is done.

  4. 4

    Find Daniel's server

    DNS MX lookup

    The provider asks DNS for the MX record of example.net, the part after the @. MX means mail exchanger: the server that takes mail for that domain.

  5. 5

    Relay on port 25

    Server to server

    The provider connects to mx.example.net on port 25 and repeats the same conversation, without a login. Servers use STARTTLS here too when both sides support it.

  6. 6

    Delivered

    250 queued, then into the mailbox

    The receiving server answers 250 and takes responsibility for the mail. It files it in Daniel's mailbox, where his app later reads it with IMAP or POP3.

Wrong password

3 steps

Ravi changed his password but his phone still has the old one, so the server refuses to take the mail.

  1. 1

    Connect and lock

    587, EHLO, STARTTLS

    Everything starts as normal: greeting, EHLO and STARTTLS. The login is offered only once TLS is on.

  2. 2

    Login refused

    535 5.7.8

    The server checks the username and password and says no with 535. The mail never leaves the phone, so the app keeps it in the Outbox.

  3. 3

    Nothing sent

    The app asks for the new password

    Without a login the server will not relay mail to other domains, or it would be an open relay that spammers love. The phone shows an error and waits for the right password.

Spoofed sender

4 steps

A stranger's server pretends to be Ravi. SPF, DKIM and DMARC catch it and the mail is rejected.

  1. 1

    A fake sender connects

    Claims to be example.com

    SMTP itself lets any server write any sender address. This server at 192.0.2.66 has nothing to do with example.com, but says MAIL FROM ravi@example.com.

  2. 2

    SPF check

    Is this IP allowed to send for example.com?

    The receiver reads example.com's SPF record from DNS. It lists the addresses allowed to send for the domain. 192.0.2.66 is not one of them, so SPF fails.

  3. 3

    DKIM and DMARC

    No valid signature, policy says reject

    The message has no DKIM signature from example.com either. The DMARC record tells receivers what to do when both checks fail for the From domain: here p=reject.

  4. 4

    550 rejected

    The mail never reaches the inbox

    The receiver refuses the message with a 5xx code while the sender is still connected. Daniel never sees the fake invoice.

Mailbox full

3 steps

Omar's mailbox is over its limit. The provider retries for days, then sends Ravi a bounce.

  1. 1

    Try to deliver

    RCPT TO gets 452

    Ravi's provider connects to the receiver on port 25 as usual. When it names omar@example.net, the receiver answers 452 4.2.2: the mailbox is full. A 4xx code means try again later.

  2. 2

    Keep it and retry

    The mail waits in the queue

    The provider keeps the mail and retries, waiting longer between each try. Omar may clear space in the meantime and the mail would then go through.

  3. 3

    Give up and bounce

    A delivery report back to Ravi

    After the retry window ends, often around five days, the provider stops and sends Ravi a bounce, a report that the mail could not be delivered. Had the receiver said 552 5.2.2 instead, a permanent error, the bounce would come at once.

Myths and mix-ups

  • Your phone does not send mail on port 25; apps use 587 or 465 with a login, and many home networks block 25.
  • The From line does not prove who sent a mail; SMTP lets anyone write any address, which is why SPF, DKIM and DMARC exist.
  • STARTTLS is not end-to-end encryption; each server along the way can still read the message.
  • A mail that is not delivered at once is not lost; on a 4xx error servers retry for days before bouncing.
  • SMTP does not fetch your inbox; IMAP or POP3 does that.

Try it yourself

Run these on your own computer to see SMTP at work.

  • Find a domain's mail server

    dig MX example.com +short

    Shows the MX records. example.com answers 0 . which means it accepts no mail at all.

  • Read SPF and DMARC records

    dig TXT example.com +short && dig TXT _dmarc.example.com +short

    Look for v=spf1 and v=DMARC1. Try it on your own email domain.

  • Talk to a submission server

    openssl s_client -starttls smtp -connect smtp.example.com:587 -crlf -quiet

    Replace the host with your provider's SMTP server. Type EHLO test and press Enter to see its extensions, then QUIT.

  • See the path a mail took

    Open any email, choose Show original or View source

    Read the Received lines from the bottom up, and the SPF, DKIM and DMARC results near the top.

SMTP at a glance

Layer
Application (7)
Ports
25 (server to server), 587 (submission with STARTTLS), 465 (submission with TLS from the start)
Transport
TCP
Format
Text commands, 3-digit reply codes
Reply classes
2xx done, 3xx send more, 4xx try later, 5xx failed
Sender checks
SPF, DKIM and DMARC, all published in DNS
First defined
1982 (RFC 821), current RFC 5321 from 2008

Defined inRFC 5321RFC 5322RFC 6409RFC 3207RFC 8314RFC 7208RFC 6376RFC 7489

Header fields

What SMTP puts in its messages, with example values from the stories above.

SMTP

Reply code
2202xx means fine. 220 is the greeting.
Text
smtp.example.com ESMTP ready
Command
EHLOEHLO (extended hello) asks the server to list its extensions. A phone with no host name uses its address in brackets.
Argument
[192.168.1.20]

Test yourself

Question 1 of 5Score 0

Which port does a mail app normally use to send new mail?

Questions people ask

What is the difference between SMTP, IMAP and POP3?

SMTP sends mail and moves it between servers. IMAP and POP3 let your app read the mail waiting in your mailbox. IMAP keeps it on the server for every device; POP3 usually downloads it to one.

Should I use port 587 or 465?

Both are fine for sending from an app. 465 starts with TLS right away, which RFC 8314 now prefers. 587 starts plain and upgrades with STARTTLS. Use what your provider lists.

Why is port 25 blocked on my home internet?

Infected home computers used to send spam straight to mail servers on port 25. Many providers block it, so you send through your mail provider on 587 or 465 instead.

What are SPF, DKIM and DMARC?

SPF lists which servers may send for a domain. DKIM adds a signature that proves the domain sent the message and it was not changed. DMARC ties them to the visible From address and says what to do when they fail.

Is email encrypted?

Usually each hop is encrypted with TLS, so people on the network cannot read it. But the mail servers themselves can. For end-to-end privacy you need something like S/MIME or OpenPGP.

What does a 550 error mean when sending email?

A permanent refusal. Common reasons are a mailbox that does not exist, a blocked sender, or a failed SPF, DKIM or DMARC check. The text after the code says which.

Donate