Postfix+Dovecotのインストール(その2)

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 = 
※後で設定する「virtual_mailbox_domains」とドメイン名が重複しているとログにエラーが表示されるので、この項目を空にしておく。
■home_mailbox
home_mailbox = Maildir/

それから行末に以下を追加します。
virtual_mailbox_domains = sanosoft.net
                          sakura.mx
virtual_mailbox_maps = hash:/etc/postfix/virtual-mailbox
virtual_uid_maps = static:10000
virtual_gid_maps = static:10000
virtual_mailbox_base = /var/spool/virtual
 
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

sasldb2のグループをpostfixに変更します。
# chgrp postfix /etc/sasldb2

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 = plain login

■ 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

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

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

(5) ユーザ登録時に自動的に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):(パスワード)



最終更新:2016年09月06日 08:30