VineLinuxパフォーマンスアッププロジェクト:0196
■DovecotでIMAPサーバの構築■
これまでPostfixとqpopperを利用したメールサーバの構築をご紹介しましたが、今回はメールサーバ上でメールの送受信ができるIMAPサーバの構築についてご紹介します。
●IMAPサーバとは?
「メールの送受信」というと、送信のためのSMTPサーバと、受信のためのPOPサーバが有名ですが、メールサーバ上の電子メールにアクセスし操作するIMAPサーバというものも存在します。
Webメール(Yahoo!メールやGoogleのGMail)、さらには以前当サイトで紹介したSquirrelMailなどを想像していただけるとわかりやすいかもしれません。Webメールはサーバにログインしてメールの送受信を行います。そのために必要となるのがIMAPサーバと呼ばれるものです。
以前、SqirrelMailを利用したWebメール構築法でcourier-imapを利用したIMAPサーバの構築法を少しご紹介しましたが、今回はDovecotという別のIMAPサーバを利用してみることにします。
●Dovecotのインストール
DovecotはVineLinuxをフルパッケージでインストールした場合、デフォルトでインストールされています。インストールされていない場合はapt-getコマンドやSynaptic等でインストールしてください。
●Dovecotの設定ファイルの編集
Dovecotの設定ファイルは、VineLinux6.0以降の場合は/etc/dovecot/dovecot.conf、VineLinux5.2以前の場合は/etc/dovecot.confです。これをrootユーザ権限でテキストエディタ等で開き、以下の2点を編集します。
*protocolsの設定
# Protocols we want to be serving: imap imaps pop3 pop3s
# If you only want to use dovecot-auth, you can set this to "none".
protocols = imap imaps pop3 pop3s ←コメントアウトを外す
*mail_locationの設定
##
## Mailbox locations and namespaces
##
# 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
# 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 ←コメントアウトを外す
●Postfixとメールボックスの設定
まず、Postfixの設定を変更します。こちらのページに従ってcourier-imapを利用した環境が整っている場合、設定は不要です。以下の記載は読み飛ばして「●Dovecotの起動」へ進んでください。
Postfixの設定ファイルである/etc/postfix/main.cfをテキストエディタ等で開き、以下の記述を修正します。
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox ←コメントアウトする
home_mailbox = Maildir/ ←コメントアウトをはずす
# The mail_spool_directory parameter specifies the directory where
# UNIX-style mailboxes are kept. The default setting depends on the
# system type.
#
#mail_spool_directory = /var/mail
#mail_spool_directory = /var/spool/mail ←コメントアウトする
さらに、メールボックスの設定をします。既存のユーザに対しては、それぞれのユーザ権限で以下のコマンドを実行します。
/usr/sbin/maildirmake Maildir
また、今後新規ユーザが作成された場合に自動的にメールボックスも作成されるように、rootユーザ権限で以下のコマンドを実行します。
mkdir -p /etc/skel/Maildir/{new,cur,tmp}
chmod -R 700 /etc/skel/Maildir/
●Dovecotの起動
courier-imapがすでに導入されている場合、IMAPサーバのポート番号がかち合うため、Dovecotが正常に起動できません。そのため、courier-imapを起動しないように設定します。
以下のコマンドを実行します。
/sbin/chkconfig courier-imap off
その後、すべての設定を反映するために、一度システムを再起動します。
再起動時に[OK]が出れば問題ありません。[failed]が出た場合、/var/log/messagesにその記録が記載されていますので、内容を確認の上、もう一度設定を見直してください。
★2011/8/12 追記
以前のバージョンのDovecotで使っていた設定ファイルを流用する場合、設定ファイルのバージョンの互換性の関係でうまく起動できない場合があります。そんな時には設定ファイルを再作成するコマンドがありますので、こちらのページを参考にしてみてください。