Dovecot IMAP/POP3 Server
Overview
- What you’ll learn: How to install and configure Dovecot as an IMAP/POP3 server on Ubuntu — including mailbox formats, TLS encryption, user authentication, and integration with Postfix for a complete mail system.
- Prerequisites: Email Protocols (SMTP, IMAP, POP3), Postfix Mail Transfer Agent, basic Linux administration
- Estimated reading time: 18 minutes
Introduction
While Postfix handles the sending and receiving of email via SMTP, users need a way to access their mailboxes from email clients such as Thunderbird, Outlook, or mobile apps. This is where Dovecot comes in. Dovecot is a high-performance, security-focused IMAP and POP3 server that allows users to retrieve and manage their email stored on the server.
Dovecot is the most widely used IMAP/POP3 server on Linux and is the default choice on Ubuntu. It integrates seamlessly with Postfix, providing both mailbox delivery (via the Dovecot LDA or LMTP) and SASL authentication for SMTP clients.
In this lesson, you will learn how to install Dovecot, configure it for IMAP access with TLS encryption, set up mailbox storage using the Maildir format, and integrate it with Postfix to create a functional mail server stack.
Installing Dovecot
Dovecot is available in Ubuntu’s default repositories. You typically install the core package along with the IMAP module. If you also need POP3 support, install the POP3 module as well.
# Install Dovecot with IMAP and POP3 support
$ sudo apt update
$ sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
# For LMTP delivery integration with Postfix
$ sudo apt install dovecot-lmtpd -y
# Verify installation and version
$ dovecot --version
2.3.16 (7e2e900c1a)
# Check service status
$ sudo systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
Loaded: loaded (/lib/systemd/system/dovecot.service; enabled)
Active: active (running)
# Verify Dovecot is listening on IMAP and POP3 ports
$ sudo ss -tlnp | grep dovecot
LISTEN 0 100 0.0.0.0:143 0.0.0.0:* users:(("dovecot",pid=2345,fd=21))
LISTEN 0 100 0.0.0.0:993 0.0.0.0:* users:(("dovecot",pid=2345,fd=23))
LISTEN 0 100 0.0.0.0:110 0.0.0.0:* users:(("dovecot",pid=2345,fd=25))
LISTEN 0 100 0.0.0.0:995 0.0.0.0:* users:(("dovecot",pid=2345,fd=27))
Dovecot Configuration Structure
Dovecot uses a modular configuration structure. The main configuration file is /etc/dovecot/dovecot.conf, which includes files from /etc/dovecot/conf.d/. Each file in conf.d/ handles a specific aspect of configuration:
- 10-auth.conf: Authentication mechanisms and password databases.
- 10-mail.conf: Mailbox location and format settings.
- 10-master.conf: Service definitions (ports, sockets, processes).
- 10-ssl.conf: TLS/SSL certificate and protocol settings.
- 15-lda.conf: Local Delivery Agent configuration.
- 20-imap.conf / 20-pop3.conf: Protocol-specific settings.
# List all configuration files
$ ls /etc/dovecot/conf.d/
10-auth.conf 10-mail.conf 10-master.conf 10-ssl.conf
15-lda.conf 15-mailboxes.conf 20-imap.conf 20-pop3.conf
90-quota.conf auth-system.conf.ext
# View the effective configuration
$ doveconf -n
Configuring Mailbox Storage
Dovecot supports multiple mailbox formats. The two most common are mbox (all messages in a single file) and Maildir (each message as a separate file in a directory structure). Maildir is strongly recommended for production use because it is more reliable, does not require file locking, and performs better with IMAP.
# Edit /etc/dovecot/conf.d/10-mail.conf
# Set Maildir as the mailbox format
# Messages stored in ~/Maildir/ for each user
mail_location = maildir:~/Maildir
# Automatically create and subscribe to default folders
namespace inbox {
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = Drafts
}
mailbox Sent {
auto = subscribe
special_use = Sent
}
mailbox Trash {
auto = subscribe
special_use = Trash
}
mailbox Junk {
auto = subscribe
special_use = Junk
}
}
Ensure this matches the home_mailbox setting in Postfix’s main.cf:
# In /etc/postfix/main.cf — must match Dovecot's mail_location
home_mailbox = Maildir/
TLS Encryption
All IMAP and POP3 connections should be encrypted with TLS. Dovecot supports both STARTTLS (upgrading a plaintext connection) and implicit TLS (encrypted from the start on ports 993/995).
# Edit /etc/dovecot/conf.d/10-ssl.conf
# Require SSL/TLS
ssl = required
# Certificate and key paths (using Let's Encrypt)
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
# Minimum TLS version
ssl_min_protocol = TLSv1.2
# Prefer server cipher order
ssl_prefer_server_ciphers = yes
# Strong cipher suite
ssl_cipher_list = ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
Postfix Integration via LMTP and SASL
For a complete mail stack, Dovecot integrates with Postfix in two ways: delivering mail via LMTP (Local Mail Transfer Protocol) and providing SASL authentication so Postfix can verify SMTP client credentials.
# --- Dovecot LMTP Service ---
# Edit /etc/dovecot/conf.d/10-master.conf
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
}
# --- Dovecot SASL for Postfix ---
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
# --- Postfix side: /etc/postfix/main.cf ---
# Use Dovecot LMTP for local delivery
mailbox_transport = lmtp:unix:private/dovecot-lmtp
# Use Dovecot for SASL authentication
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
After making changes, restart both services:
# Restart Dovecot and Postfix
$ sudo systemctl restart dovecot
$ sudo systemctl restart postfix
# Test IMAP login
$ openssl s_client -connect mail.example.com:993
a1 LOGIN user@example.com password
a1 OK [CAPABILITY IMAP4rev1 ...] Logged in
# Test with doveadm
$ sudo doveadm mailbox list -u user@example.com
INBOX
Sent
Drafts
Trash
Junk
Key Takeaways
- Dovecot is the standard IMAP/POP3 server on Linux, providing mailbox access for email clients; it uses a modular configuration structure under
/etc/dovecot/conf.d/. - The Maildir format (one file per message) is recommended over mbox for production use; set
mail_location = maildir:~/Maildirand match Postfix’shome_mailbox. - TLS should be set to
requiredwith a minimum of TLSv1.2; use Let’s Encrypt certificates for both Dovecot and Postfix. - Dovecot integrates with Postfix via LMTP for mail delivery and SASL for SMTP authentication, using Unix sockets in Postfix’s chroot directory.
- Use
doveconf -nto verify effective configuration anddoveadmfor mailbox management, user lookup, and troubleshooting.
What’s Next
In the next lesson, you will learn about email security mechanisms — SPF, DKIM, and DMARC — that protect your domain from spoofing and improve mail deliverability.
繁體中文
概述
- 學習目標:學習如何在 Ubuntu 上安裝和設定 Dovecot 作為 IMAP/POP3 伺服器,包括信箱格式、TLS 加密、使用者身份驗證,以及與 Postfix 的整合以建立完整的郵件系統。
- 先決條件:電子郵件協定(SMTP、IMAP、POP3)、Postfix 郵件傳輸代理、基本 Linux 管理
- 預計閱讀時間:18 分鐘
簡介
雖然 Postfix 處理透過 SMTP 發送和接收電子郵件,但使用者需要一種方式從電子郵件用戶端(如 Thunderbird、Outlook 或行動應用程式)存取他們的信箱。這就是 Dovecot 的用武之地。Dovecot 是一個高效能、注重安全的 IMAP 和 POP3 伺服器,允許使用者擷取和管理儲存在伺服器上的電子郵件。
Dovecot 是 Linux 上使用最廣泛的 IMAP/POP3 伺服器,也是 Ubuntu 上的預設選擇。它與 Postfix 無縫整合,提供信箱投遞(透過 Dovecot LDA 或 LMTP)和 SMTP 用戶端的 SASL 身份驗證。
在本課程中,您將學習如何安裝 Dovecot、設定具有 TLS 加密的 IMAP 存取、使用 Maildir 格式設定信箱儲存,以及與 Postfix 整合以建立功能完整的郵件伺服器堆疊。
安裝 Dovecot
Dovecot 可在 Ubuntu 的預設儲存庫中取得。通常安裝核心套件以及 IMAP 模組。如果還需要 POP3 支援,請同時安裝 POP3 模組。
# 安裝具有 IMAP 和 POP3 支援的 Dovecot
$ sudo apt update
$ sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
# 用於與 Postfix 的 LMTP 投遞整合
$ sudo apt install dovecot-lmtpd -y
# 驗證安裝和版本
$ dovecot --version
2.3.16 (7e2e900c1a)
# 檢查服務狀態
$ sudo systemctl status dovecot
Dovecot 設定結構
Dovecot 使用模組化設定結構。主設定檔是 /etc/dovecot/dovecot.conf,它包含 /etc/dovecot/conf.d/ 中的檔案。conf.d/ 中的每個檔案處理設定的特定方面:
- 10-auth.conf:身份驗證機制和密碼資料庫。
- 10-mail.conf:信箱位置和格式設定。
- 10-master.conf:服務定義(連接埠、通訊端、行程)。
- 10-ssl.conf:TLS/SSL 憑證和協定設定。
設定信箱儲存
Dovecot 支援多種信箱格式。最常見的兩種是 mbox(所有郵件在單一檔案中)和 Maildir(每封郵件作為目錄結構中的獨立檔案)。Maildir 強烈建議用於生產環境,因為它更可靠、不需要檔案鎖定,且與 IMAP 配合效能更好。
# 編輯 /etc/dovecot/conf.d/10-mail.conf
# 設定 Maildir 作為信箱格式
mail_location = maildir:~/Maildir
# 自動建立和訂閱預設資料夾
namespace inbox {
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = Drafts
}
mailbox Sent {
auto = subscribe
special_use = Sent
}
mailbox Trash {
auto = subscribe
special_use = Trash
}
}
TLS 加密
所有 IMAP 和 POP3 連線都應使用 TLS 加密。Dovecot 支援 STARTTLS(升級純文字連線)和 implicit TLS(從一開始就在連接埠 993/995 上加密)。
# 編輯 /etc/dovecot/conf.d/10-ssl.conf
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
ssl_min_protocol = TLSv1.2
ssl_prefer_server_ciphers = yes
透過 LMTP 和 SASL 與 Postfix 整合
對於完整的郵件堆疊,Dovecot 以兩種方式與 Postfix 整合:透過 LMTP 投遞郵件,以及提供 SASL 身份驗證讓 Postfix 可以驗證 SMTP 用戶端憑證。
# Dovecot LMTP 服務 — 編輯 /etc/dovecot/conf.d/10-master.conf
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
}
# Dovecot SASL for Postfix
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
# 重新啟動兩個服務
$ sudo systemctl restart dovecot
$ sudo systemctl restart postfix
重點摘要
- Dovecot 是 Linux 上的標準 IMAP/POP3 伺服器,為電子郵件用戶端提供信箱存取;它在
/etc/dovecot/conf.d/下使用模組化設定結構。 - Maildir 格式(每封郵件一個檔案)建議用於生產環境;設定
mail_location = maildir:~/Maildir並匹配 Postfix 的home_mailbox。 - TLS 應設定為
required,最低版本為 TLSv1.2;為 Dovecot 和 Postfix 使用 Let’s Encrypt 憑證。 - Dovecot 透過 LMTP 進行郵件投遞和 SASL 進行 SMTP 身份驗證與 Postfix 整合,使用 Postfix chroot 目錄中的 Unix 通訊端。
- 使用
doveconf -n驗證有效設定,使用doveadm進行信箱管理、使用者查詢和故障排除。
下一步
在下一課中,您將學習電子郵件安全機制——SPF、DKIM 和 DMARC——這些機制保護您的網域免受偽造並改善郵件投遞能力。
日本語
概要
- 学習内容:Ubuntu での Dovecot の IMAP/POP3 サーバーとしてのインストールと設定方法を学びます。メールボックス形式、TLS 暗号化、ユーザー認証、Postfix との統合を含みます。
- 前提条件:メールプロトコル(SMTP、IMAP、POP3)、Postfix メール転送エージェント、基本的な Linux 管理
- 推定読了時間:18分
はじめに
Postfix が SMTP 経由でメールの送受信を処理する一方、ユーザーは Thunderbird、Outlook、モバイルアプリなどのメールクライアントからメールボックスにアクセスする方法が必要です。ここで Dovecot の出番です。Dovecot は高性能でセキュリティ重視の IMAP および POP3 サーバーであり、ユーザーがサーバーに保存されたメールを取得・管理できるようにします。
Dovecot は Linux で最も広く使用されている IMAP/POP3 サーバーであり、Ubuntu のデフォルトの選択肢です。Postfix とシームレスに統合し、メールボックス配信(Dovecot LDA または LMTP 経由)と SMTP クライアントの SASL 認証の両方を提供します。
このレッスンでは、Dovecot のインストール、TLS 暗号化による IMAP アクセスの設定、Maildir 形式でのメールボックスストレージの設定、Postfix との統合による機能的なメールサーバースタックの構築方法を学びます。
Dovecot のインストール
Dovecot は Ubuntu のデフォルトリポジトリで利用可能です。通常、コアパッケージと IMAP モジュールをインストールします。POP3 サポートも必要な場合は、POP3 モジュールもインストールします。
# IMAP と POP3 サポート付きで Dovecot をインストール
$ sudo apt update
$ sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
# Postfix との LMTP 配信統合用
$ sudo apt install dovecot-lmtpd -y
# インストールとバージョンの確認
$ dovecot --version
2.3.16 (7e2e900c1a)
# サービス状態の確認
$ sudo systemctl status dovecot
Dovecot 設定構造
Dovecot はモジュラーな設定構造を使用します。メインの設定ファイルは /etc/dovecot/dovecot.conf で、/etc/dovecot/conf.d/ からファイルをインクルードします。
- 10-auth.conf:認証メカニズムとパスワードデータベース。
- 10-mail.conf:メールボックスの場所と形式の設定。
- 10-master.conf:サービス定義(ポート、ソケット、プロセス)。
- 10-ssl.conf:TLS/SSL 証明書とプロトコルの設定。
メールボックスストレージの設定
Dovecot は複数のメールボックス形式をサポートしています。最も一般的な2つは mbox(すべてのメッセージが単一ファイル)と Maildir(各メッセージがディレクトリ構造内の個別ファイル)です。Maildir は信頼性が高く、ファイルロックが不要で、IMAP とのパフォーマンスが優れているため、本番環境に強く推奨されます。
# /etc/dovecot/conf.d/10-mail.conf を編集
# Maildir をメールボックス形式として設定
mail_location = maildir:~/Maildir
# デフォルトフォルダを自動作成・購読
namespace inbox {
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = Drafts
}
mailbox Sent {
auto = subscribe
special_use = Sent
}
mailbox Trash {
auto = subscribe
special_use = Trash
}
}
TLS 暗号化
すべての IMAP および POP3 接続は TLS で暗号化する必要があります。
# /etc/dovecot/conf.d/10-ssl.conf を編集
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
ssl_min_protocol = TLSv1.2
ssl_prefer_server_ciphers = yes
LMTP と SASL による Postfix 統合
完全なメールスタックのために、Dovecot は2つの方法で Postfix と統合します:LMTP によるメール配信と、Postfix が SMTP クライアントの資格情報を検証できるようにする SASL 認証の提供です。
# Dovecot LMTP サービス — /etc/dovecot/conf.d/10-master.conf を編集
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
}
# Postfix 用 Dovecot SASL
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
# 両方のサービスを再起動
$ sudo systemctl restart dovecot
$ sudo systemctl restart postfix
重要ポイント
- Dovecot は Linux の標準 IMAP/POP3 サーバーで、メールクライアントにメールボックスアクセスを提供します。
/etc/dovecot/conf.d/下のモジュラー設定構造を使用します。 - Maildir 形式(メッセージごとに1ファイル)が本番環境に推奨されます。
mail_location = maildir:~/Maildirを設定し、Postfix のhome_mailboxと一致させてください。 - TLS は
requiredに設定し、最小 TLSv1.2 にする必要があります。Dovecot と Postfix の両方に Let’s Encrypt 証明書を使用します。 - Dovecot は LMTP によるメール配信と SASL による SMTP 認証で Postfix と統合し、Postfix の chroot ディレクトリ内の Unix ソケットを使用します。
doveconf -nで有効な設定を確認し、doveadmでメールボックス管理、ユーザー検索、トラブルシューティングを行います。
次のステップ
次のレッスンでは、ドメインのなりすましを防ぎ、メール配信性を向上させるメールセキュリティメカニズム——SPF、DKIM、DMARC——について学びます。