Email Protocols: SMTP, IMAP, POP3

Level: Intermediate Module: Mail Services 7 min read Lesson 28 of 66

Overview

  • What you’ll learn: The fundamental email protocols SMTP, IMAP, and POP3 — their purpose, how they interact, the ports they use, and how email flows from sender to recipient across the Internet.
  • Prerequisites: Basic Linux networking concepts (TCP/IP, ports, DNS)
  • Estimated reading time: 15 minutes

Introduction

Email is one of the oldest and most essential services on the Internet, dating back to the early days of ARPANET. Despite the rise of instant messaging and collaboration platforms, email remains the backbone of business communication and is a critical service for system administrators to understand and manage.

At its core, email relies on a small set of well-defined protocols that handle two distinct tasks: sending mail and retrieving mail. Understanding these protocols is the foundation for deploying, configuring, and troubleshooting any mail server infrastructure.

In this lesson, we will explore the three primary email protocols — SMTP, IMAP, and POP3 — examining how each works, the ports they use, and how they cooperate to deliver email from a sender’s client to a recipient’s inbox.

SMTP: Simple Mail Transfer Protocol

SMTP (Simple Mail Transfer Protocol) is the standard protocol for sending email across the Internet. Defined originally in RFC 821 and updated in RFC 5321, SMTP is responsible for transferring messages from a mail client to a mail server, and from one mail server to another until the message reaches its destination.

SMTP operates on a client-server model using a series of text-based commands and responses. The protocol follows a store-and-forward approach: each server in the chain accepts the message and either delivers it locally or forwards it to the next server closer to the destination.

SMTP Ports and Security

  • Port 25: The traditional SMTP port for server-to-server (relay) communication. Many ISPs block outbound port 25 to reduce spam.
  • Port 587: The submission port for authenticated clients sending mail through their mail server. This is the recommended port for mail user agents (MUAs).
  • Port 465: Originally assigned for SMTPS (SMTP over implicit TLS), deprecated, then re-assigned in RFC 8314 for submissions over TLS.
# Test SMTP connectivity to a mail server
$ telnet mail.example.com 25
Trying 203.0.113.10...
Connected to mail.example.com.
220 mail.example.com ESMTP Postfix

EHLO client.example.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-STARTTLS
250-AUTH PLAIN LOGIN
250 8BITMIME

MAIL FROM:<sender@example.com>
250 2.1.0 Ok

RCPT TO:<recipient@example.com>
250 2.1.5 Ok

DATA
354 End data with <CR><LF>.<CR><LF>
Subject: Test Email
From: sender@example.com
To: recipient@example.com

This is a test email.
.
250 2.0.0 Ok: queued as ABC123

QUIT
221 2.0.0 Bye

The example above demonstrates a complete SMTP conversation. The client introduces itself with EHLO, specifies the sender and recipient with MAIL FROM and RCPT TO, sends the message body after DATA, and terminates with QUIT.

MX Records and Mail Routing

When an SMTP server needs to deliver mail to a remote domain, it queries DNS for the domain’s MX (Mail Exchanger) records. MX records specify which servers accept email for a domain and their priority:

# Query MX records for a domain
$ dig +short MX example.com
10 mail1.example.com.
20 mail2.example.com.

# Trace the full DNS lookup
$ host -t MX example.com
example.com mail is handled by 10 mail1.example.com.
example.com mail is handled by 20 mail2.example.com.

The server with the lowest priority number is tried first. If it is unavailable, the sending server falls back to higher-numbered servers.

IMAP: Internet Message Access Protocol

IMAP (Internet Message Access Protocol), currently at version 4 revision 1 (IMAP4rev1, RFC 3501), is a protocol for retrieving and managing email on a remote server. Unlike POP3, IMAP is designed to keep messages stored on the server, allowing users to access their email from multiple devices while maintaining a consistent view of their mailbox.

IMAP supports advanced features such as server-side folder management, message flagging, partial message fetching, and server-side search. These features make IMAP the preferred protocol for modern email clients.

IMAP Ports

  • Port 143: Standard IMAP port; supports STARTTLS upgrade to encrypted communication.
  • Port 993: IMAPS — IMAP over implicit TLS for fully encrypted connections from the start.
# Test IMAP connectivity
$ openssl s_client -connect mail.example.com:993
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE] Dovecot ready.

a1 LOGIN user@example.com password
a1 OK [CAPABILITY IMAP4rev1 SORT THREAD=REFERENCES] Logged in

a2 LIST "" "*"
* LIST (HasNoChildren) "." "INBOX"
* LIST (HasNoChildren) "." "Sent"
* LIST (HasNoChildren) "." "Drafts"
* LIST (HasNoChildren) "." "Trash"
a2 OK List completed.

a3 SELECT INBOX
* 42 EXISTS
* 0 RECENT
* FLAGS (Answered Flagged Deleted Seen Draft)
a3 OK [READ-WRITE] Select completed.

a4 LOGOUT
* BYE Logging out
a4 OK Logout completed.

POP3: Post Office Protocol Version 3

POP3 (Post Office Protocol version 3, RFC 1939) is a simpler protocol for downloading email from a server to a local client. The fundamental design philosophy of POP3 is “download and delete” — messages are transferred to the client and typically removed from the server, though most modern clients can be configured to leave copies on the server.

POP3 is best suited for single-device access scenarios where the user wants to store all email locally. It does not support server-side folders, message flagging, or any of the advanced management features that IMAP provides.

POP3 Ports

  • Port 110: Standard POP3 port; supports STARTTLS upgrade.
  • Port 995: POP3S — POP3 over implicit TLS.
# Test POP3 connectivity
$ openssl s_client -connect mail.example.com:995
+OK Dovecot ready.

USER user@example.com
+OK

PASS password
+OK Logged in.

STAT
+OK 42 1234567

LIST
+OK 42 messages:
1 4520
2 8730
3 2100
.

RETR 1
+OK 4520 octets
Return-Path: <sender@example.com>
Subject: Hello
...message content...
.

QUIT
+OK Logging out.

Key Takeaways

  • SMTP (ports 25, 587, 465) handles sending and relaying email between servers; it uses text-based commands like EHLO, MAIL FROM, RCPT TO, and DATA.
  • IMAP (ports 143, 993) retrieves and manages mail on the server, supporting folders, flags, and multi-device access — the preferred modern retrieval protocol.
  • POP3 (ports 110, 995) downloads mail to a local client, following a simpler “download and delete” model suited for single-device access.
  • DNS MX records direct SMTP servers to the correct destination mail server for a given domain, with priority-based failover.
  • All three protocols support TLS encryption — either via STARTTLS upgrade or implicit TLS on dedicated ports — and should always be configured securely in production.

What’s Next

In the next lesson, you will learn about Postfix, one of the most widely used Mail Transfer Agents on Linux, and how to configure it to send and receive email on Ubuntu Server.

繁體中文

概述

  • 學習目標:了解基本電子郵件協定 SMTP、IMAP 和 POP3——它們的用途、互動方式、使用的連接埠,以及電子郵件如何在網際網路上從寄件者傳送到收件者。
  • 先決條件:基本的 Linux 網路概念(TCP/IP、連接埠、DNS)
  • 預計閱讀時間:15 分鐘

簡介

電子郵件是網際網路上最古老且最重要的服務之一,可追溯到 ARPANET 的早期時代。儘管即時通訊和協作平台不斷興起,電子郵件仍然是商業通訊的骨幹,也是系統管理員必須理解和管理的關鍵服務。

電子郵件的核心依賴一小組定義明確的協定,這些協定處理兩個不同的任務:發送郵件和接收郵件。理解這些協定是部署、設定和排除任何郵件伺服器基礎設施問題的基礎。

在本課程中,我們將探討三個主要的電子郵件協定——SMTP、IMAP 和 POP3——研究每個協定的工作方式、使用的連接埠,以及它們如何協作將電子郵件從寄件者的用戶端傳送到收件者的收件匣。

SMTP:簡單郵件傳輸協定

SMTP(Simple Mail Transfer Protocol,簡單郵件傳輸協定)是在網際網路上發送電子郵件的標準協定。最初定義於 RFC 821,並在 RFC 5321 中更新,SMTP 負責將郵件從郵件用戶端傳輸到郵件伺服器,以及從一個郵件伺服器傳輸到另一個,直到郵件到達目的地。

SMTP 使用基於文字的命令和回應,採用用戶端-伺服器模型運作。該協定遵循儲存轉發方式:鏈中的每個伺服器接受郵件,然後將其在本地投遞或轉發到離目的地更近的下一個伺服器。

SMTP 連接埠和安全性

  • 連接埠 25:傳統的 SMTP 連接埠,用於伺服器對伺服器(中繼)通訊。許多 ISP 封鎖出站連接埠 25 以減少垃圾郵件。
  • 連接埠 587:提交連接埠,供經過身份驗證的用戶端通過其郵件伺服器發送郵件。這是郵件使用者代理(MUA)的建議連接埠。
  • 連接埠 465:最初分配給 SMTPS(SMTP over implicit TLS),後來被棄用,然後在 RFC 8314 中重新分配用於通過 TLS 提交郵件。
# 測試與郵件伺服器的 SMTP 連線
$ telnet mail.example.com 25
Trying 203.0.113.10...
Connected to mail.example.com.
220 mail.example.com ESMTP Postfix

EHLO client.example.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-STARTTLS
250-AUTH PLAIN LOGIN
250 8BITMIME

MAIL FROM:<sender@example.com>
250 2.1.0 Ok

RCPT TO:<recipient@example.com>
250 2.1.5 Ok

QUIT
221 2.0.0 Bye

MX 記錄和郵件路由

當 SMTP 伺服器需要將郵件投遞到遠端網域時,它會查詢 DNS 以獲取該網域的 MX(郵件交換器)記錄。MX 記錄指定哪些伺服器接受該網域的電子郵件及其優先順序:

# 查詢網域的 MX 記錄
$ dig +short MX example.com
10 mail1.example.com.
20 mail2.example.com.

優先順序數字最低的伺服器會先被嘗試。如果該伺服器不可用,發送伺服器會退回到數字較高的伺服器。

IMAP:網際網路訊息存取協定

IMAP(Internet Message Access Protocol,網際網路訊息存取協定),目前版本為 4 修訂版 1(IMAP4rev1,RFC 3501),是一種在遠端伺服器上擷取和管理電子郵件的協定。與 POP3 不同,IMAP 設計為將郵件保存在伺服器上,允許使用者從多個裝置存取電子郵件,同時保持郵箱的一致檢視。

IMAP 支援進階功能,如伺服器端資料夾管理、郵件標記、部分郵件擷取和伺服器端搜尋。這些功能使 IMAP 成為現代電子郵件用戶端的首選協定。

IMAP 連接埠

  • 連接埠 143:標準 IMAP 連接埠;支援 STARTTLS 升級到加密通訊。
  • 連接埠 993:IMAPS——IMAP over implicit TLS,從一開始就提供完全加密連線。

POP3:郵局協定第 3 版

POP3(Post Office Protocol version 3,郵局協定第 3 版,RFC 1939)是一種較簡單的協定,用於從伺服器下載電子郵件到本地用戶端。POP3 的基本設計理念是「下載並刪除」——郵件傳輸到用戶端後通常從伺服器刪除,但大多數現代用戶端可以設定為在伺服器上保留副本。

POP3 最適合單一裝置存取的場景,使用者希望在本地儲存所有郵件。它不支援伺服器端資料夾、郵件標記或 IMAP 提供的任何進階管理功能。

POP3 連接埠

  • 連接埠 110:標準 POP3 連接埠;支援 STARTTLS 升級。
  • 連接埠 995:POP3S——POP3 over implicit TLS。

重點摘要

  • SMTP(連接埠 25、587、465)處理伺服器之間的電子郵件發送和中繼;使用 EHLO、MAIL FROM、RCPT TO 和 DATA 等文字命令。
  • IMAP(連接埠 143、993)在伺服器上擷取和管理郵件,支援資料夾、標記和多裝置存取——是現代首選的擷取協定。
  • POP3(連接埠 110、995)將郵件下載到本地用戶端,遵循較簡單的「下載並刪除」模式,適合單一裝置存取。
  • DNS MX 記錄將 SMTP 伺服器導向給定網域的正確目的地郵件伺服器,具有基於優先順序的故障轉移。
  • 三種協定都支援 TLS 加密——通過 STARTTLS 升級或專用連接埠上的 implicit TLS——在生產環境中應始終安全設定。

下一步

在下一課中,您將學習 Postfix——Linux 上最廣泛使用的郵件傳輸代理之一,以及如何在 Ubuntu Server 上設定它來發送和接收電子郵件。

日本語

概要

  • 学習内容:基本的なメールプロトコル SMTP、IMAP、POP3——その目的、相互作用の仕組み、使用するポート、そしてメールがインターネット上で送信者から受信者にどのように流れるかを理解します。
  • 前提条件:基本的な Linux ネットワーク概念(TCP/IP、ポート、DNS)
  • 推定読了時間:15分

はじめに

メールは ARPANET の初期にまで遡る、インターネット上で最も古く、最も重要なサービスの一つです。インスタントメッセージングやコラボレーションプラットフォームの台頭にもかかわらず、メールはビジネスコミュニケーションの基盤であり続け、システム管理者が理解し管理すべき重要なサービスです。

メールの核心は、送信受信という2つの異なるタスクを処理する、明確に定義された少数のプロトコルに依存しています。これらのプロトコルを理解することは、メールサーバーインフラストラクチャの展開、設定、トラブルシューティングの基盤です。

このレッスンでは、3つの主要なメールプロトコル——SMTP、IMAP、POP3——を探求し、それぞれの動作、使用するポート、そして送信者のクライアントから受信者の受信トレイにメールを配信するためにどのように連携するかを検討します。

SMTP:Simple Mail Transfer Protocol

SMTP(Simple Mail Transfer Protocol)は、インターネット上でメールを送信するための標準プロトコルです。元々 RFC 821 で定義され、RFC 5321 で更新された SMTP は、メールクライアントからメールサーバーへ、そしてメッセージが宛先に到達するまで一つのメールサーバーから別のサーバーへメッセージを転送する役割を担います。

SMTP はテキストベースのコマンドと応答を使用するクライアント・サーバーモデルで動作します。このプロトコルはストアアンドフォワード方式に従います:チェーン内の各サーバーがメッセージを受け入れ、ローカルに配信するか、宛先に近い次のサーバーに転送します。

SMTP ポートとセキュリティ

  • ポート 25:サーバー間(リレー)通信用の従来の SMTP ポート。多くの ISP はスパム削減のためにアウトバウンドポート 25 をブロックしています。
  • ポート 587:認証されたクライアントがメールサーバー経由でメールを送信するための送信ポート。メールユーザーエージェント(MUA)に推奨されるポートです。
  • ポート 465:元々 SMTPS(暗黙的 TLS 上の SMTP)に割り当てられ、廃止された後、RFC 8314 で TLS 上の送信用に再割り当てされました。
# メールサーバーへの SMTP 接続テスト
$ telnet mail.example.com 25
Trying 203.0.113.10...
Connected to mail.example.com.
220 mail.example.com ESMTP Postfix

EHLO client.example.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-STARTTLS
250-AUTH PLAIN LOGIN
250 8BITMIME

MAIL FROM:<sender@example.com>
250 2.1.0 Ok

RCPT TO:<recipient@example.com>
250 2.1.5 Ok

QUIT
221 2.0.0 Bye

MX レコードとメールルーティング

SMTP サーバーがリモートドメインにメールを配信する必要がある場合、そのドメインの MX(Mail Exchanger)レコードを DNS に問い合わせます。MX レコードは、ドメインのメールを受け入れるサーバーとその優先度を指定します:

# ドメインの MX レコードを照会
$ dig +short MX example.com
10 mail1.example.com.
20 mail2.example.com.

優先度番号が最も低いサーバーが最初に試行されます。利用できない場合、送信サーバーは番号の高いサーバーにフォールバックします。

IMAP:Internet Message Access Protocol

IMAP(Internet Message Access Protocol)は、現在バージョン 4 リビジョン 1(IMAP4rev1、RFC 3501)で、リモートサーバー上のメールを取得および管理するためのプロトコルです。POP3 とは異なり、IMAP はメッセージをサーバーに保存するよう設計されており、ユーザーは複数のデバイスからメールにアクセスしながら、メールボックスの一貫したビューを維持できます。

IMAP はサーバー側のフォルダ管理、メッセージフラグ付け、部分的なメッセージ取得、サーバー側検索などの高度な機能をサポートしています。

IMAP ポート

  • ポート 143:標準 IMAP ポート。STARTTLS による暗号化通信へのアップグレードをサポート。
  • ポート 993:IMAPS——最初から完全に暗号化された接続を提供する暗黙的 TLS 上の IMAP。

POP3:Post Office Protocol バージョン 3

POP3(Post Office Protocol version 3、RFC 1939)は、サーバーからローカルクライアントにメールをダウンロードするためのよりシンプルなプロトコルです。POP3 の基本的な設計哲学は「ダウンロードして削除」です——メッセージはクライアントに転送され、通常サーバーから削除されますが、ほとんどの最新クライアントではサーバーにコピーを残すよう設定できます。

POP3 は、ユーザーがすべてのメールをローカルに保存したい単一デバイスアクセスのシナリオに最適です。サーバー側のフォルダ、メッセージフラグ付け、IMAP が提供する高度な管理機能はサポートしていません。

POP3 ポート

  • ポート 110:標準 POP3 ポート。STARTTLS アップグレードをサポート。
  • ポート 995:POP3S——暗黙的 TLS 上の POP3。

重要ポイント

  • SMTP(ポート 25、587、465)はサーバー間のメール送信とリレーを処理し、EHLO、MAIL FROM、RCPT TO、DATA などのテキストコマンドを使用します。
  • IMAP(ポート 143、993)はサーバー上でメールを取得・管理し、フォルダ、フラグ、マルチデバイスアクセスをサポート——現代の推奨取得プロトコルです。
  • POP3(ポート 110、995)はメールをローカルクライアントにダウンロードし、単一デバイスアクセスに適したシンプルな「ダウンロードして削除」モデルに従います。
  • DNS MX レコードは、指定されたドメインの正しい宛先メールサーバーに SMTP サーバーを誘導し、優先度ベースのフェイルオーバーを提供します。
  • 3つのプロトコルすべてが TLS 暗号化をサポートしており——STARTTLS アップグレードまたは専用ポートでの暗黙的 TLS を介して——本番環境では常に安全に設定する必要があります。

次のステップ

次のレッスンでは、Linux で最も広く使用されているメール転送エージェントの一つである Postfix と、Ubuntu Server でメールの送受信を設定する方法について学びます。

You Missed