LoginSignup
13
22

More than 5 years have passed since last update.

CentOS 7 の Dovecot で受信メールサーバー構築

Posted at

CentOS 7 で Dovecot を利用して独自ドメインのメールを受信できるようにする最低限の設定についての解説。SMTP 認証や暗号化については別の記事でまとめる予定。

Postfix については「CentOS 7 の Postfix で独自ドメインの設定 - Qiita」を参照。

Dovecot


Dovecot は Linux/UNIX 系システム用に書かれたオープンソースの IMAP および POP3 サーバーである。 1
いわゆる受信メールサーバーに当たり、 MRA (Mail Retrieval Agent) と呼ばれることもある。他に Courier などがある。

Dovecot を MDA (Mail Delivery Agent) と紹介している記事が多いが、 CentOS の標準の MDA は Procmail になる。 2 3

Open email survey (2019) の調査によると、343万台の IMAP サーバーの内 Dovecot は76%のシェアを占める。

リファレンス

firewalld の設定

firewall-cmd --list-services && \
firewall-cmd --add-service={pop,imap} --permanent && \
firewall-cmd --reload && \
firewall-cmd --list-services

Dovecot のインストール

Dovecot は Postfix と異なりデフォルトでは CentOS にインストールされていない。 IMAP または POP3 サーバーとして機能させるためには Dovecot をインストールする必要がある。

利用可能なリポジトリ

パッケージでインストールする場合は、標準リポジトリ、Dovecot 公式リポジトリGhettoForge リポジトリIUS Community リポジトリの4つのリポジトリが主に利用できる。

標準リポジトリ

CentOS の標準リポジトリでは Dovecot 2.2.36 がインストールされる。
利用可能なパッケージは以下の通り。

パッケージ名 概要
dovecot Secure imap and pop3 server
dovecot-devel Development files for dovecot
dovecot-mysql MySQL back end for dovecot
dovecot-pgsql Postgres SQL back end for dovecot
dovecot-pigeonhole Sieve and managesieve plug-in for dovecot

Dovecot 公式リポジトリ

cat << "_EOF_" >> /etc/yum.repos.d/dovecot.repo
[dovecot-2.3-latest]
name=Dovecot 2.3 CentOS $releasever - $basearch
baseurl=http://repo.dovecot.org/ce-2.3-latest/centos/$releasever/RPMS/$basearch
gpgkey=https://repo.dovecot.org/DOVECOT-REPO-GPG
gpgcheck=1
enabled=1
_EOF_

Dovecot 公式リポジトリでは Dovecot 2.3.4-2 がインストールされる。
利用可能なパッケージは以下の通り。 4

パッケージ名 概要
dovecot
dovecot-debuginfo
dovecot-devel
dovecot-imaptest
dovecot-imaptest-debuginfo
dovecot-lua
dovecot-mysql
dovecot-pgsql
dovecot-pigeonhole
dovecot-pigeonhole-debuginfo
dovecot-pigeonhole-devel

GhettoForge リポジトリ

yum install http://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el7.noarch.rpm

GhettoForge Plus リポジトリでは dovecot23 パッケージで Dovecot 2.3.4-1 がインストールされる。
インストール可能なパッケージは以下の通り。

パッケージ名 概要
dovecot23 Secure imap and pop3 server
dovecot23-devel Development files for dovecot
dovecot23-mysql MySQL back end for dovecot
dovecot23-pgsql Postgres SQL back end for dovecot
dovecot23-pigeonhole Sieve and managesieve plug-in for dovecot

IUS Community リポジトリ

IUS Community リポジトリでは dovecot22u パッケージで Dovecot 2.2.36-1 がインストールされる。
インストール可能なパッケージは以下の通り。

パッケージ名 概要
dovecot22u Secure imap and pop3 server
dovecot22u-devel Development files for dovecot
dovecot22u-mysql MySQL back end for dovecot
dovecot22u-pgsql Postgres SQL back end for dovecot
dovecot22u-pigeonhole Sieve and managesieve plug-in for dovecot

インストールと自動起動設定

yum --assumeyes install dovecot && \
systemctl enable dovecot

依存関係で clucene-core パッケージが同時にインストールされる。

Dovecot の設定と起動

DOMAIN=example.jp && \
doveconf | egrep "^(auth_mechanisms|disable_plaintext_auth|mail_location|ssl) " && \
sed -i.org /etc/dovecot/conf.d/10-mail.conf \
    -e '/#mail_location/ s/^#//' \
    -e '|^mail_location| s|$|maildir:~/Maildir|' && \
sed -i.org /etc/dovecot/conf.d/10-auth.conf \
    -e '/#disable_plaintext_auth/ s/^#//' \
    -e '/^disable_plaintext_auth/ s/yes/no/' \
    -e '/^auth_mechanisms/ s/plain$/plain login/' && \
sed -i.org /etc/dovecot/conf.d/10-ssl.conf \
    -e '/^ssl =/ s/required/yes/' && \
dovecot check && \
systemctl start dovecot && \
doveconf | egrep "^(auth_mechanisms|disable_plaintext_auth|mail_location|ssl) "

mail_location

mail_location のデフォルトは空で、以下の順序で自動検出を試みる。 5

  • ~/mdbox/
  • ~/sdbox/
  • ~/Maildir/
  • ~/mail/.imap/
  • ~/mail/inbox
  • ~/mail/mbox
  • ~/Mail/.imap/
  • ~/Mail/inbox
  • ~/Mail/mbox

自動検出がうまく動作するとしても、特に新規ユーザーのフォルダーの自動生成の観点から、通常はメールの場所を明示的に指定することが望ましい。 6

ssl

Dovecot はデフォルトで SSL を使用するため、SSL なしの認証を許可するには SSL を無効にする必要がある。 7
また同時に disable_plaintext_auth でプレーンテキスト認証を許可する必要がある。 8
yes, no, required の値が認識される。 9

sslrequire が指定されていると、 disable_plaintext_authno でも mc dovecot: pop3-login: Disconnected: Inactivity (tried to use disallowed plaintext auth): といったエラーが出力される。

disable_plaintext_auth

LOGINDISABLED 機能により SSL/TLS が使用されていない限り LOGIN コマンドおよび他のすべてのプレーンテキスト認証を無効にする。 10
デフォルトではプレーンテキスト認証が許可されていないので、SSL なしの認証を許可したい場合は disable_plaintext_authno に指定して許可する必要がある。 8
リモート IP がローカル IP と一致する(同じコンピュータから接続している)場合、接続は安全と見なされプレーンテキスト認証が許可される。 11

auth_mechanisms

auth_mechanisms はデフォルトでは PLAIN メカニズムのみが有効。 12
SSL で保護された接続内で暗号化されていないパスワードを送信しても問題はないので、SSL を使用していれば PLAIN メカニズム以外を気にする必要はない。 13

LOGIN メカニズムも暗号化されず、通常 Outlook クライアントに SMTP 認証を実行させるために、 SMTP サーバーによってのみ使用される。 14

動作確認

IMAP

curl --verbose telnet://mail.example.jp:143
curl --verbose telnet://127.0.0.1:143

POP3

curl --verbose telnet://mail.example.jp:110
curl --verbose telnet://127.0.0.1:110

  1. "Dovecot is an open source IMAP and POP3 email server for Linux/UNIX-like systems, written with security primarily in mind." -
    Dovecot
     

  2. "Red Hat Enterprise Linux には、Procmail がプライマリー MDA となります。" - 15.4. メール配信エージェント(MDA) - Red Hat Customer Portal 

  3. "Procmail is often installed as the default LDA." - procmail - Dovecot Wiki 

  4. "If you are installing new installation, you can use following package names" - CentOS packages - Dovecot community software repository 

  5. "By default the mail_location setting is empty, which means that Dovecot attempts to locate automatically where your mails are. This is done by looking, in order, at:" - Autodetection - MailLocation - Dovecot Wiki 

  6. "It's usually a good idea to explicitly specify where the mails are, even if the autodetection happens to work, in particular to benefit from auto-creation of the folder for new users." - Autodetection - MailLocation - Dovecot Wiki 

  7. "To allow any Authentication without SSL, disable SSL in the conf.d/10-ssl.conf file. This has to be done because Dovecot (now) uses SSL as default." - Plaintext Authentication - BasicConfiguration - Dovecot Wiki 

  8. "Until SSL is configured, allow plaintext authentication in the conf.d/10-auth.conf file. " - Plaintext Authentication - BasicConfiguration - Dovecot Wiki 

  9. "SSL/TLS support: yes, no, required." - core/10-ssl.conf at master-2.2 · dovecot/core 

  10. "Disable LOGIN command and all other plaintext authentications unless SSL/TLS is used (LOGINDISABLED capability)." - core/10-auth.conf at master-2.2 · dovecot/core 

  11. "Note that if the remote IP matches the local IP (ie. you're connecting from the same computer), the connection is considered secure and plaintext authentication is allowed." - core/10-auth.conf at master-2.2 · dovecot/core 

  12. "By default only PLAIN mechanism is enabled." - Configuration - Authentication/Mechanisms - Dovecot Wiki 

  13. "Today however many people use SSL/TLS, and there's no problem with sending unencrypted password inside SSL secured connections. So if you're using SSL, you probably don't need to bother worrying about anything else than the PLAIN mechanism." - Authentication/Mechanisms - Dovecot Wiki 

  14. "Another plaintext mechanism is LOGIN. It's typically used only by SMTP servers to let Outlook clients perform SMTP authentication." - Authentication/Mechanisms - Dovecot Wiki 

13
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
22