〜 安定したメール受信の要となるPOP/IMAPサーバー構築 〜
目次
🧭 概要
Dovecot(ドヴコット) は、IMAP(Internet Message Access Protocol) や POP3(Post Office Protocol) に対応したメール受信用サーバー(MDA)です。PostfixなどのMTAと連携して、ユーザーのメールボックスからメールを配信します。
- 軽量・高速
- セキュア(TLS/SSL対応)
- Maildir形式やmbox形式に対応
- 管理ツールが豊富(doveadm、doveconf)
🛠️ 1. インストールと起動
インストール(例:Debian/Ubuntu)
sudo apt update
sudo apt install dovecot-imapd dovecot-pop3d
サービス管理
sudo systemctl enable dovecot
sudo systemctl start dovecot
sudo systemctl status dovecot
📁 2. Dovecotの設定ファイル構成
| ディレクトリ/ファイル | 内容 |
|---|---|
/etc/dovecot/dovecot.conf | メイン設定ファイル(include 指定) |
/etc/dovecot/conf.d/ | サブ設定ファイル群(分割管理) |
/etc/dovecot/conf.d/10-auth.conf | 認証関連の設定 |
/etc/dovecot/conf.d/10-mail.conf | メールボックスの形式/場所 |
/etc/dovecot/conf.d/10-ssl.conf | SSL/TLSの設定 |
/var/mail/ または ~/Maildir/ | メールボックスの保存先 |
⚙️ 3. メール形式と保存場所の設定(10-mail.conf)
mail_location = maildir:~/Maildir
maildir:… 推奨される高速・安全な形式mbox:… 古い形式(1ファイルにまとめる)
🔐 4. 認証方式の設定(10-auth.conf)
disable_plaintext_auth = yes
auth_mechanisms = plain login
disable_plaintext_auth = yes:暗号化なしの平文認証を禁止auth_mechanisms:使用する認証方式(通常plainとlogin)
認証方法には /etc/passwd や仮想ユーザー(SQL/LDAP)も使用可能。
📡 5. POP3 と IMAP の有効化(10-master.conf)
ポート番号:
| プロトコル | ポート | 説明 |
|---|---|---|
| POP3 | 110 | 通常のPOP3 |
| POP3S | 995 | SSL付きPOP3 |
| IMAP | 143 | 通常のIMAP |
| IMAPS | 993 | SSL付きIMAP |
基本は protocols 行で指定:
protocols = imap pop3
🔒 6. TLS/SSL の基本設定(10-ssl.conf)
ssl = required
ssl_cert = </etc/ssl/certs/mail.crt
ssl_key = </etc/ssl/private/mail.key
ssl = required:TLS/SSL接続を必須にするssl_cert:証明書ファイルのパスssl_key:秘密鍵ファイルのパス
自己署名証明書を作成する例:
openssl req -new -x509 -days 365 -nodes \
-out /etc/ssl/certs/mail.crt \
-keyout /etc/ssl/private/mail.key
🔧 7. ツール紹介
| コマンド | 役割 |
|---|---|
doveconf | 設定の確認・出力 |
doveadm | メールボックス管理・ユーザー診断 |
例:
doveconf -n
(有効な設定のみ出力)
doveadm user user1
(指定ユーザーの状態確認)
📑 8. ログとトラブルシューティング
| ログファイル | 内容 |
|---|---|
/var/log/mail.log | メール送受信や認証情報 |
/var/log/syslog または journalctl | サービス全体のログ |
tail -f /var/log/mail.log
✅ まとめ
| 項目 | 設定ポイント |
|---|---|
| インストール | dovecot-imapd, dovecot-pop3d パッケージ |
| メール保存形式 | mail_location(Maildir推奨) |
| 認証 | 10-auth.conf で機構を設定 |
| SSL/TLS | 10-ssl.conf で秘密鍵・証明書を指定 |
| サービス確認 | doveconf, doveadm, journalctl |
コメント