Dovecotの設定(CentOS 7)

Dovecot というソフトウェアを使用して、受信メールサーバを構築します。

環境

CentOS 7.2.X
Dovecot 2.2.X

1.Dovecotのインストール

Dovecotをインストールします。

[root@ ~]# yum -y install dovecot

2.Dovecotの設定ファイル編集(dovecot.conf)

設定ファイル/etc/dovecot/dovecot.confを編集します。

[root@ ~]# vi /etc/dovecot/dovecot.conf

「protocols = imap pop3 lmtp」の行頭に#を追加し、この行を無効にして、その下に「protocols = imap pop3」を追加します。
「listen = *, ::」の行頭に#を追加し、この行を無効にして、その下に「listen = *」を追加します。

## Dovecot configuration file

# If you're in a hurry, see http://wiki2.dovecot.org/QuickConfiguration

# "doveconf -n" command gives a clean output of the changed settings. Use it
# instead of copy&pasting files when posting to the Dovecot mailing list.

# '#' character and everything after it is treated as comments. Extra spaces
# and tabs are ignored. If you want to use either of these explicitly, put the
# value inside quotes, eg.: key = "# char and trailing whitespace  "

# Most (but not all) settings can be overridden by different protocols and/or
# source/destination IPs by placing the settings inside sections, for example:
# protocol imap { }, local 127.0.0.1 { }, remote 10.0.0.0/8 { }

# Default values are shown for each setting, it's not required to uncomment
# those. These are exceptions to this though: No sections (e.g. namespace {})
# or plugin settings are added by default, they're listed only as examples.
# Paths are also just examples with the real defaults being based on configure
# options. The paths listed here are for configure --prefix=/usr
# --sysconfdir=/etc --localstatedir=/var

# Protocols we want to be serving.
#protocols = imap pop3 lmtp
protocols = imap pop3

# A comma separated list of IPs or hosts where to listen in for connections.
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
# If you want to specify non-default ports or anything more complex,
# edit conf.d/master.conf.
#listen = *, ::
listen = *

# Base directory where to store runtime data.
#base_dir = /var/run/dovecot/

3.Dovecotの設定ファイル編集(10-mail.conf)

設定ファイル/etc/dovecont/conf.d/10-mail.confを編集します。

[root@ ~]# vi /etc/dovecot/conf.d/10-mail.conf

「mail_location = maildir:~/Maildir」を追加します。

##
## Mailbox locations and namespaces
##

# Location for users' mailboxes. The default is empty, which means that Dovecot
# tries to find the mailboxes automatically. This won't work if the user
# doesn't yet have any mail, so you should explicitly tell Dovecot the full
# location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# kept. This is called the "root mail directory", and it must be the first
# path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
#   %u - username
#   %n - user part in user@domain, same as %u if there's no domain
#   %d - domain part in user@domain, empty if there's no domain
#   %h - home directory
#
# See doc/wiki/Variables.txt for full list. Some examples:
#
#   mail_location = maildir:~/Maildir
#   mail_location = mbox:~/mail:INBOX=/var/mail/%u
#   mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# <doc/wiki/MailLocation.txt>
#
#mail_location =
mail_location = maildir:~/Maildir

4.Dovecotの設定ファイル編集(10-auth.conf)

設定ファイル/etc/dovecot/conf.d/10-auth.confを編集します。

[root@ ~]# vi /etc/dovecot/conf.d/10-auth.conf

「disable_plaintext_auth = no」を追加します。

##
## Authentication processes
##

# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). 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.
# See also ssl=required setting.
#disable_plaintext_auth = yes
disable_plaintext_auth = no

5.Dovecotの設定ファイル編集(10-ssl.conf)

設定ファイル/etc/dovecont/conf.d/10-ssl.confを編集します。

[root@ ~]# vi /etc/dovecont/conf.d/10-ssl.conf

SSLを使用しないので、「ssl = no」にします。

##
## SSL settings
##

# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
ssl = no

6.Dovecotの起動と自動起動設定

[root@ ~]# systemctl start dovecot
[root@ ~]# systemctl enable dovecot

Dovecotの設定は以上です。

7.PostfixとDovecotの通信許可

PostfixとDovecotの通信を許可します。
送信ポート(25・587)、POP受信ポート(110)、IMAP受信ポート(143)を許可設定します。
設定を反映させるため、必ずリロードします。

[root@ ~]# firewall-cmd --permanent --zone=public --add-port=25/tcp
success
[root@ ~]# firewall-cmd --permanent --zone=public --add-port=587/tcp
success
[root@ ~]# firewall-cmd --permanent --zone=public --add-port=110/tcp
success
[root@ ~]# firewall-cmd --permanent --zone=public --add-port=143/tcp
success
[root@ ~]# firewall-cmd --reload
success

8.メール専用ユーザの追加

PostfixとDovecotの設定が完了したので、メール専用ユーザを追加します。
※例として、testuserを追加します。

[root@ ~]# useradd -s /sbin/nologin testuser
[root@ ~]# passwd testuser
Changing password for user testuser.
New UNIX password: (パスワード入力)
Retype new UNIX password: (パスワード確認)

[root@ ~]# echo '(パスワード入力)' | saslpasswd2 -p -u mail.example.com -c testuser(SMTP-Auth用ユーザ・パスワードの登録)

[root@ ~]# sasldblistusers2(SMTP-Auth用ユーザ名・パスワードの確認)
testuser@mail.example.com: userPassword

下記のコマンドでsasldb2の所有グループをpostfixにします。※初回のみ

[root@ ~]# chgrp postfix /etc/sasldb2   

メール専用ユーザの追加は以上です。