Postfix+Dovecotのインストール

PostfixとDovecotでメールサーバを構築します。
※CentOS7で構築しますので、他のOSの場合はコマンドを読み替えて下さい。

1. Postfixのインストール

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

(1) インストール
# yum install postfix

(2) main.cfの編集
「/etc/postfix/main.cf」ファイルを編集します。
# cd /etc/postfix
# vi main.cf

■myhostname
myhostname = mail.example.com
■mydomain
mydomain = example.com
■myorigin
myorigin = $mydomain
■inet_interfaces
inet_interfaces = all
■inet_protocols
inet_protocols = ipv4
■mydestination
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
mail.$mydomain, www.$mydomain, ftp.$mydomain
■home_mailbox
home_mailbox = Maildir/

それから行末に以下を追加します。
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination
smtpd_sasl_security_options = noanonymous
 
message_size_limit = 10240000
mailbox_size_limit = 102400000

(3) master.cfの編集
「/etc/postfix/master.cf」ファイルを編集します。
ここではサブミッションポートの設定を行います。
# cd /etc/postfix
# vi master.cf

submission inet n       -       n       -       -       smtpd
#  -o syslog_name=postfix/submission
#  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_reject_unlisted_recipient=no
#  -o smtpd_client_restrictions=$mua_client_restrictions
#  -o smtpd_helo_restrictions=$mua_helo_restrictions
#  -o smtpd_sender_restrictions=$mua_sender_restrictions
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING

(4) postfixのサービスの起動
postfixのサービスを起動します。
# systemctl start postfix.service

postfixの自動起動の設定を行います。
# systemctl enable postfix.service

(5) エイリアス設定
「webmaster」、「info」などのメールアカウントを利用したい場合にはエイリアス設定を無効にします。
「/etc/aliases」ファイルを編集します。
# vi /etc/aliases

該当のアカウントをコメントにします。
#webmaster:	root
#info:		postmaster

「/etc/aliases.db」を更新します。
# newaliases

(6) SMTP認証クライアントのインストール
SMTP認証クライアントとしてCyrusをインストールします。
# yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-md5

(6) SMTP認証クライアントのインストール
ここではSTMP認証ユーザおよびパスワードは、Linuxのアカウントではなく、SASL独自のパスワードデータベースで管理します。
そこで「/etc/sasl2/smtpd.conf」を編集します。
# vi /etc/sasl2/smtpd.conf

#pwcheck_method: saslauthd
pwcheck_method: auxprop
#mech_list: plain login
mech_list: cram-md5 plain login

sasldb2のグループをpostfixに変更します。
# chgrp postfix /etc/sasldb2
※ユーザの登録が1件もない場合にはこのファイルが存在していない可能性があります。その場合にはユーザを登録後にこの設定を行って下さい。

saslauthdサービスを停止します。
# systemctl stop saslauthd.service
# systemctl disable saslauthd.service

(7) saslのコマンド
■ユーザー登録
# /usr/sbin/saslpasswd2 -u mail.example.com -c (ユーザー名)
※-uのドメインは、postfixのmain.cfの「smtpd_sasl_local_domain」で指定したものと同じ値にします。この値が一致しないと認証に失敗します。
■ユーザー削除
# /usr/sbin/saslpasswd2 -u mail.example.com -d (ユーザー名)
■登録している認証ユーザーの確認
# /usr/sbin/sasldblistusers2

2. Dovecotのインストール

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

(1) インストール
# yum install dovecot

(2) dovecot.confの設定
「/etc/devecot/dovecot.conf」を編集します。
protocols = imap pop3
listen = *

(3) /etc/dovecot/conf.dの各ファイルの設定
■10-auth.conf
disable_plaintext_auth = no
auth_mechanisms = cram-md5 plain login
#!include auth-deny.conf.ext
#!include auth-master.conf.ext

!include auth-system.conf.ext
#!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext

■ 10-mail.conf
mail_location = maildir:~/Maildir

■ 10-master.conf
service pop3-login {
  inet_listener pop3 {
    port = 110
  }
  inet_listener pop3s {
    #port = 995
    #ssl = yes
  }
}
service auth {
・・・ () ・・・
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }
 
  # Auth process is run as this user.
  #user = $default_internal_user
}
 

■ 10-ssl.conf
ssl = no

■ auth-passwdfile.conf.ext
passdb {
    driver = passwd-file
    args = /etc/dovecot/users
}
 
userdb {
    driver = passwd-file
    args = /etc/dovecot/users
 
    # Default fields that can be overridden by passwd-file
    #default_fields = quota_rule=*:storage=1G
 
    # Override fields from passwd-file
    #override_fields = home=/home/virtual/%u
}
 

(4) CRAM-MD5ユーザファイルの作成
CRAM-MD5のパスワードを生成します。
# doveadm pw -s CRAM-MD5
Enter new password: (パスワード入力)
Retype new password: (同じパスワードをもう一度)
※ここでのパスワードはsaslpasswd2で作成したパスワードと同じにします。

以下のようなパスワード文字列が生成されます。(※この文字列はサンプルです。)
{CRAM-MD5}072c56cabbc67d2399eeaec47e5962395de0b711ab6f76366f6b80d5671cde47

前述の「auth-passwdfile.conf.ext」で記載したパス名でパスワードファイルを作成し、ユーザー情報および生成したパスワードをファイルに書き込みます。
# vi /etc/dovecot/users

書式は、以下の通りです。
ユーザ名):{CRAM-MD5}(生成したパスワード文字列)
【例】
info:{CRAM-MD5}072c56cabbc67d2399eeaec47e5962395de0b711ab6f76366f6b80d5671cde47

作成したパスワードファイルのオーナーをdovecotにします。
# chown dovecot:dovecot users

(5) dovecotのサービスの起動
dovecotのサービスを起動します。
# systemctl start dovecot.service

dovecotの自動起動の設定を行います。
# systemctl enable dovecot.service

(6) ユーザ登録時に自動的にMaildirを作成する場合
ユーザ登録時に自動的にMaildirが作成されるようにします。
# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
# chmod -R 700 /etc/skel/Maildir/

3. メール用アカウントの作成

ここでは「info」ユーザを作成してみます。
※パスワードは、すべて同じにします。

(1) OSユーザの作成
# groupadd info
# useradd -g info -d /home/info -s /bin/bash -m info
# passwd info

(2) SASL認証用のアカウントとパスワードを作成
# saslpasswd2 -u mail.example.com info
Password:(パスワード)
Again (for verification):(パスワード)

(3) CRAM-MD5用のアカウントとパスワードを作成
# doveadm pw -s CRAM-MD5
# vi /etc/dovecot/users





最終更新:2016年09月20日 14:04