はじめての自宅サーバ構築 - Fedora/CentOS -
Last Update 2017/02/18
[ 更新履歴 ] [ サイト マップ ] [ 質問掲示板 ] [ 雑談掲示板 ] [ リンク ]
トップ >> メールサーバ >> メールサーバ(POP/IMAP)の構築(Dovecot)
動作確認 [ FC1 / FC2 / FC3 / FC4 / FC5 / FC6 / Fedora7 / Fedora8 / Fedora9 / Fedora10 / Fedora11 / Fedora12 / Fedora13 / Fedora14 / Fedora15 / Fedora16 / Fedora17 / CentOS4 / CentOS5 / CentOS6 / CentOS7 ]
  1. dovecotとは・・・
  2. dovecotのインストール
  3. dovecotの設定
    dovecot Ver 2.0未満の場合
    dovecot Ver 2.0の場合
  4. dovecotの起動
  5. OSの再起動を行なった時にdovecot(POPサーバ)を自動的に起動するように設定する
  6. 接続前の準備
  7. クライアントメールソフトの設定
    設定例(Becky!)
  8. こんな時は・・・

■ dovecotとは・・・

dovecotとは、POPサーバ(受信メールサーバ)機能を提供するパッケージです。
また、POPサーバとは逆に送信メールサーバを構築するには、『メールサーバ(SMTP)の構築(Postfix)』をご覧ください。

■ dovecotのインストール

# yum -y install dovecot

■ dovecotの設定

dovecot Ver2 より設定ファイルが分散型(機能別)になりました。
設定箇所が違うので、現在のdovecotバージョンを確認します。

dovecot バージョンの確認
# rpm -qa dovecot

dovecot-1.0.15-16.fc9.x86_64
上記の場合は、Ver 1.0となり、下記の場合は、Ver 2.0となります。
dovecot-2.0.1-1.fc14.x86_64

■ dovecot Ver 2.0未満の場合

設定ファイルの編集
# vi /etc/dovecot.conf
プロトコルを指定
# Protocols we want to be serving:
protocols = imap imaps pop3 pop3s

メールボックス(Maildir)を各ユーザのホームディレクトリに配置
*************************************************************************************
* dovecot Ver 1.0から属性名「default_mail_env」が「mail_location」に変更されました。*
* バージョンは以下のコマンドで確認できます                                          *
* # rpm -qa dovecot                                                                 *
* dovecot-1.0-1.rc15.fc6                                                            *
*************************************************************************************

【dovecot Ver 1.0未満( Ver < 1.0 )の場合】
# Default MAIL environment to use when it's not set. By leaving this empty
# dovecot tries to do some automatic detection as described in
# doc/mail-storages.txt. There's a few special variables you can use:
#
#   %u - username
#   %n - user part in user@domain, same as %u if there's no domain
#   %d - domain part in user@domain, empty if user there's no domain
#   %h - home directory
#
# You can also limit a width of string by giving the number of max. characters
# after the '%' character. For example %1u gives the first character of
# username. Some examples:
#
#   maildir:/var/mail/%1u/%u/Maildir
#   mbox:~/mail/:INBOX=/var/mail/%u
#   mbox:/var/mail/%d/%n/:INDEX=/var/indexes/%d/%n
#
default_mail_env = maildir:~/Maildir

【dovecot Ver 1.0の場合】
# Location for users' mailboxes. This is the same as the old default_mail_env
# setting. The default is empty, which means that Dovecot tries to find the
# mailboxes automatically. This won't work if the user doesn't have any mail
# yet, 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
# and where Dovecot can place its index files. 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/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
#
# http://wiki.dovecot.org/MailLocation
#
mail_location = maildir:~/Maildir

chrootユーザのディレクトリ
# ':' separated list of directories under which chrooting is allowed for mail
# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
# This setting doesn't affect login_chroot or auth_chroot variables.
# WARNING: Never add directories here which local users can modify, that
# may lead to root exploit. Usually this should be done only if you don't
# allow shell access for users. See doc/configuration.txt for more information.
valid_chroot_dirs = /home


Dovecot Ver 1.0から POP3 UIDL format が変わったらしい。
メールログ「/var/log/maillog」に以下が出力され、メーラより取得する事が出来ない。
Jun  8 21:31:38 fedora dovecot: POP3(linux): pop3_uidl_format setting is missing from config file
Jun  8 21:31:38 fedora dovecot: child 2741 (pop3) returned error 89

以下のコマンドを実施して バージョンが 1.0であれば、以下の変更が必要
# rpm -qa dovecot
dovecot-1.0-0.beta8.1.fc5

# vi /etc/dovecot.conf
  # POP3 UIDL format to use. You can use following variables:
  #
  #  %v - Mailbox UIDVALIDITY
  #  %u - Mail UID
  #  %m - MD5 sum of the mailbox headers in hex (mbox only)
  #  %f - filename (maildir only)
  #
  # If you want UIDL compatibility with other POP3 servers, use:
  #  UW's ipop3d         : %08Xv%08Xu
  #  Courier version 0   : %f
  #  Courier version 1   : %u
  #  Courier version 2   : %v-%u
  #  Cyrus (<= 2.1.3)    : %u
  #  Cyrus (>= 2.1.4)    : %v.%u
  #  Older Dovecots      : %v.%u
  #
  # 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.
  #
  # NOTE: Nowadays this is required to be set explicitly, since the old
  # default was bad but it couldn't be changed without breaking existing
  # installations. %08Xu%08Xv will be the new default, so use it for new
  # installations.
  #
  #pop3_uidl_format = %08Xu%08Xv
pop3_uidl_format = %u

■ dovecot Ver 2.0の場合

設定ファイルの編集
# vi /etc/dovecot/dovecot.conf
プロトコルを指定
# Protocols we want to be serving.
protocols = imap pop3


メールボックス(Maildir)を各ユーザのホームディレクトリに配置
# vi /etc/dovecot/conf.d/10-mail.conf
# 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 = maildir:~/Maildir

chrootユーザのディレクトリ
# ':' separated list of directories under which chrooting is allowed for mail
# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
# This setting doesn't affect login_chroot, mail_chroot or auth chroot
# settings. If this setting is empty, "/./" in home dirs are ignored.
# WARNING: Never add directories here which local users can modify, that
# may lead to root exploit. Usually this should be done only if you don't
# allow shell access for users. <doc/wiki/Chrooting.txt>
valid_chroot_dirs = /home


POP3 UIDL formatの指定
# vi /etc/dovecot/conf.d/20-pop3.conf
  # 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 simultaneosly)
  #  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 = %u


plaintext 認証(認証メカニズム)の指定
# vi /etc/dovecot/conf.d/10-auth.conf
# 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.
disable_plaintext_auth = no

# Space separated list of wanted authentication mechanisms:
#   plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
#   gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login

■ dovecotの起動

dovecotを起動する
【FC1 から Fedora14 / CentOS4 / CentOS5 / CentOS6 の場合】
# /etc/rc.d/init.d/dovecot start

【Fedora15以降 / CentOS7 の場合】
# systemctl start dovecot.service

■ OSの再起動を行なった時にdovecot(POPサーバ)を自動的に起動するように設定する

起動時にdovecotを起動する
【FC1 から Fedora14 / CentOS4 / CentOS5 / CentOS6 の場合】
# chkconfig dovecot on
設定内容を確認
# chkconfig --list dovecot
dovecot         0:オフ  1:オフ  2:オン  3:オン  4:オン  5:オン  6:オフ

【Fedora15以降 / CentOS7 の場合】
# systemctl enable dovecot.service
設定内容を確認
# systemctl status dovecot.service
dovecot.service - Dovecot IMAP/POP3 email server
          Loaded: loaded (/lib/systemd/system/dovecot.service; enabled)
          Active: active (running) since Tue, 15 Nov 2011 09:45:40 +0900; 16s ago
        Main PID: 1558 (dovecot)
          CGroup: name=systemd:/system/dovecot.service
                  ├ 1558 /usr/sbin/dovecot -F
                  ├ 1559 dovecot/anvil
                  ├ 1560 dovecot/log
                  └ 1562 dovecot/config

■ 接続前の準備

WANから接続するに当たって、ルータの設定が必要です。
ルータのポート開閉は、ご自分のルータ取扱説明書をご覧ください。

DNS名で接続するには事前にドメイン名の取得を行っている必要があります。(以下は代表的なものであり、また、当サイトが使用させて頂いております)

■ クライアントメールソフトの設定

当サイトで紹介している『メールサーバ(SMTP)の構築(Postfix)』は、SMTP-Auth(送信認証)を使用する様に設定しています。
よく間違えられるのは、『メールサーバ(SMTP)の構築(Postfix)[SMTP-Authユーザパスワードの設定]』で行ったそのユーザのパスワードを指定した為に認証エラーとなり取得できません。

こちらのパスワードはUNIX(Linux)アカウントのパスワードを指定します。*:SMTP-Authユーザパスワードではありません。

■ 設定例(Becky!)

当方で使用させて頂いている「Becky!」を例にあげて説明します。

メールボックスの設定で「基本設定」タブを開き、サーバー情報グループ内の以下の項目を指定します。

■ こんな時は・・・

■ コンテンツ関連

■ その他

ページ先頭へ

Copyright(©)2004-2017 First home server construction. All Right Reserved.