Course contents

Unit 7: TCP, UDP and PortsLesson 7.3.5 (20 of 23 in this unit)69 of 104 in the Network Fundamentals course

SMTP, POP3 and IMAP

One protocol to send mail and two ways to read it, with the ports each one uses.

Beginner · 7 min read

Covers SMTP, POP3 vs. IMAP and Mail ports.

Technical definition

Email protocols are the application-layer protocols that move mail. SMTP (Simple Mail Transfer Protocol) sends messages from clients to servers and between servers, while POP3 (Post Office Protocol version 3) and IMAP (Internet Message Access Protocol) let a client retrieve mail from its mailbox.

Why a new phone asks for two mail servers

You add your work email to a new phone. The setup screen asks for an “incoming server” and an “outgoing server”, each with its own port. Why two? Because sending mail and reading mail are two different jobs, done by different protocols.

One protocol sends, two retrieve

  • SMTP (Simple Mail Transfer Protocol) sends mail. Your email app uses it to hand a message to your mail server, and mail servers use it to pass the message to each other.
  • POP3 (Post Office Protocol version 3) downloads mail from the server to one device, and usually deletes it from the server (many apps can be set to keep a copy).
  • IMAP (Internet Message Access Protocol) lets you read mail that stays on the server, so every device sees the same folders and the same read or unread marks.

Follow one email

Alice (alice@example.com) writes to Bob (bob@example.net). To find Bob's mail server, Alice's server looks up the MX record (mail exchanger) for example.net in DNS.

Diagram
An email from Alice to Bob
An email from Alice to Bob
Alicemail.example.comDNSmx.example.netBob

Device key: Alice (laptop) · mail.example.com, DNS, mx.example.net (server) · Bob (mobile device)

Lines show the example’s network connections. Dashed wireless links: radio connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

  1. 1. 1. Submit. Alice's email app logs in and sends the message to her own server with SMTP on port 587.
  2. 2. 2. Find the destination. Her server asks DNS for the MX record of example.net and gets mx.example.net.
  3. 3. 3. Relay. The message moves from server to server with SMTP on port 25.
  4. 4. 4. Read. Bob's phone reads the message from his server with IMAP over TLS.

What SMTP says

SMTP is a text conversation made of short commands and three-digit reply codes. Codes starting with 2 mean OK, 3 means “go on”, 4 means a temporary error and 5 means a permanent error.

Step 1 of 5 · EHLO mail.example.com
mail.example.com
sending server
Internet
mx.example.net
198.51.100.40:25

Device key: mail.example.com, mx.example.net (server)

Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • mail.example.com: sending server
  • mx.example.net: 198.51.100.40:25

Real servers usually send STARTTLS after EHLO, so the rest of the conversation is encrypted.

Why the ports differ

Most of these protocols have a plain port and an encrypted one. Port 25 is used for server-to-server relay. Users submit mail on port 587 (or 465) and must log in, which stops strangers from using the server to send spam. Many home internet providers also block outbound port 25 from customer connections, so a mail app set to send on 25 often just times out.

Diagram
Why the ports differ
Why the ports differ
ProtocolJobPlain portEncrypted port
SMTPServer-to-server relay2525 with STARTTLS
SMTP submissionApp sends to its own server587 with STARTTLS465 (TLS from the start)
POP3Download to one device110995
IMAPRead and sync on the server143993
Read each row across: the left box names the item, the others describe it.

All of them run on TCP. POP3 made sense when most people had only one computer. Today, most people read mail on both a phone and a laptop, so IMAP is the usual choice.

Finding a domain's mail servers

Check which servers receive mail for a domain by looking up its MX records from any computer:

nslookup -type=mx example.net

List the mail servers for example.net, with their preference numbers.

Example output, shortened and written for this lesson:

example.net    mail exchanger = 10 mx.example.net.
example.net    mail exchanger = 20 mx2.example.net.

What to look for: each mail exchanger line names one mail server for the domain. The number before the name is the preference: the lower number (10, mx.example.net) is tried first, and mx2.example.net (20) is the backup. You can run the same check with the MX Lookup tool.

Test yourself on SMTP, POP3 and IMAP

Predict · scenario 1

A user at one company emails a user at another company. Which protocol moves the message from the first company's mail server to the second company's?

Predict · scenario 2

You read mail on a phone and a laptop and want both to show the same folders. Which protocol fits?

Predict · scenario 3

Your mail server must deliver a message to bob@example.net. Which DNS record does it look up to find where to send it?