Dovecotの設定

カテゴリ:POP3サーバ

CentOS/Ubuntu 両対応

基本設定

/etc/dovecot/dovecot.conf をviで開きます。

# vi /etc/dovecot/dovecot.conf

以下のパラメータを追加します。
※IMAPとPOP3を使用する場合

protocols = imap pop3
listen = *

10-mail.conf でメール形式を指定します。
※Postfix側の形式と合わせる必要があります。以下はMBOX形式の場合です。

# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = mbox:~/mail/:INBOX=/var/mail/%u

20-pop3.conf でPOP3 UIDLフォーマットを「Dovecot v0.99.x」、「Cyrus 2.1.4以上」(初期設定)に設定します。

# vi /etc/dovecot/conf.d/20-pop3.conf
pop3_uidl_format = %v.%u

なお、POP3 UIDL フォーマットについては 20-pop3.conf 内の下記コメントが参考になります。必要に応じて %08Xu%08Xv などに変更してください。

POP3 UIDL (unique mail identifier) format to use. You can use following variables, along with the variable modifiers described in doc/wiki/Variables.txt (e.g. %Uf for the filename in uppercase)

 %v - Mailbox's IMAP UIDVALIDITY
 %u - Mail's IMAP UID
 %m - MD5 sum of the mailbox headers in hex (mbox only)
 %f - filename (maildir only)
 %g - Mail's GUID

If you want UIDL compatibility with other POP3 servers, use:
 UW's ipop3d         : %08Xv%08Xu
 Courier             : %f or %v-%u (both might be used simultaneously)
 Cyrus (<= 2.1.3)    : %u
 Cyrus (>= 2.1.4)    : %v.%u
 Dovecot v0.99.x     : %v.%u
 tpop3d              : %Mf

Note that Outlook 2003 seems to have problems with %v.%u format which was Dovecot's default, so if you're building a new server it would be a good idea to change this. %08Xu%08Xv should be pretty fail-safe.

#pop3_uidl_format = %08Xu%08Xv

SSLの設定

DovecotへのSSL証明書の設定を参照してください。

PAM認証の設定

DovecotのPAM認証の設定ファイルをviで開きます。

# vi /etc/pam.d/dovecot

CentOSの場合:

以下の行を削除します。

session    include      password-auth

以下の行を追加します。

account     sufficient     pam_access.so

編集後:

# cat /etc/pam.d/dovecot
#%PAM-1.0
auth       required     pam_nologin.so
auth       include      password-auth
account    include      password-auth
account     sufficient     pam_access.so

Ubuntuの場合:

# cat /etc/pam.d/dovecot
#%PAM-1.0

@include common-auth
@include common-account
@include common-session

auth       required     pam_nologin.so
auth       include      common-auth
account    include      common-auth
account sufficient      pam_access.so

注意UbuntuではPAMサービス名がCentOSとは異なるため注意です。password-authではなく、common-authです。

Dovecotの起動

Dovecotを起動します。

# systemctl start dovecot

Dovecotのテスト

mail コマンドでユーザーにメールを送信。

# mail admin@example1.com
Subject: test
test
.
EOT

telnet で POP3 からメールを受信してみます。
telnet が入っていない場合はyumでインストールします。

CentOS 7 の場合:

# yum -y install telnet

CentOS 8 以降の場合:

# dnf -y install telnet

Ubuntu の場合:

# apt -y install telnet

telnet で localhost:110 に接続してメッセージを受信してみます。

# telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
USER example1
+OK
PASS hoge
+OK Logged in.
LIST
+OK 1 messages:
1 569
.
RETR 1
+OK 569 octets
Return-Path: 
X-Original-To: admin@example1.com
Delivered-To: example1@localhost.localdomain
Received: by localhost.localdomain (Postfix, from userid 0)
id 7B3CD260BB8; Mon, 21 Jul 2014 00:19:06 +0900 (JST)
Date: Mon, 21 Jul 2014 00:19:06 +0900
To: admin@example1.com
Subject: test
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20140720151906.7B3CD260BB8@localhost.localdomain>
From: root@localhost.localdomain (root)

test
.
QUIT
+OK Logging out.
Connection closed by foreign host.

RETRコマンドでメールを受信できれば成功です。
SSL接続を試す場合は、メーラーで以下を設定して受信します。

サーバーの種類:POP3またはIMAP
受信メールサーバー:VPSのドメイン名もしくはIPアドレス
受信ポート:995(POP3)または993(IMAP)
受信するユーザーとパスワード:該当のLinuxのユーザー名とパスワード

受信時に「Error: mkdir(/home/hoge/mail/.imap/INBOX) failed」となる場合

もし maillog に以下のようなディレクトリの作成エラーが記録されメッセージが受信できない場合は、ユーザーを mail グループに追加することで解決します。
これは、/var/spool/mail には初期設定で root ユーザーと mail グループにしか書き込み権限がないためです。
※/var/mail は /var/spool/mail へのシンボリックリンクです。

dovecot: imap(hoge): Error: chown(/home/hoge/mail/.imap/INBOX, -1, 12(mail)) failed: Operation not permitted (egid=508(hoge), group based on /var/mail/hoge)
Error: mkdir(/home/hoge/mail/.imap/INBOX) failed: Operation not permitted

以下の例では hoge ユーザーを mail グループに追加しています。
例)

# usermod -G mail hoge

公開日時:2014年07月21日 02:06:41
最終更新日時:2024年03月30日 01:18:45

なお、VPS選びで迷ったらこちらの記事で主要VPSのメモリ容量ごとの月額、年額料金を比較していますので、是非参考にしてみてください。

POP3サーバに戻る

このページのトップに戻る