Routelearn.net
Course menu

Unit 7: TCP, UDP and PortsLesson 7.3.5 (17 of 20 in this unit)50 of 84 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

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.

In simple terms: One protocol sends email and another lets you read it. SMTP delivers the message to the mail server, and POP3 or IMAP brings it to your mail app.

A situation

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.

What they are

  • 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.

💡 In simple terms: SMTP is the postal service that carries letters between post offices. POP3 empties your mailbox and takes everything home. IMAP lets you read your letters while they stay in the mailbox, so they look the same whichever device you use.

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.

Alicemail.example.comDNSmx.example.netBob
  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

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.

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

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.

How to verify it

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.

Check yourself

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?