Postfix + Dovecot でSMTP Auth (Dovecot SASL) のメール環境構築

Postfix と Dovecot を使って、メール環境を構築するときの手順を整理しておきたいと思います。MTAの認証方式には、Dovecot SASLによるSMTP Authを使用します。

Postfix は MTA(Mail Transport Agent)、Dovecot は imap/popサーバです。インストール時点のそれぞれのバージョンは次の通りです。

  • Postfix 2.3.3
  • Dovecot 1.0.7
1.Postfixのインストール
[root ~]# yum install postfix
(略)
Installed:
  postfix.i386 2:2.3.3-2.3.el5_6

Complete!
2.Postfixの設定
[root ~]# vim /etc/postfix/main.cf
パラメータ 操作 設定内容の説明
myhostname = xxx.goofoo.jp 追加する メールサーバのインターネットホスト名
mydomain = goofoo.jp 追加する ドメイン名
myorigin = $mydomain コメントを外す ローカルからのメールの送信元ドメイン名
inet_interfaces = all コメントを外す メールを受信するネットワークインターフェース
#inet_interfaces = local コメントアウトする メールを受信するネットワークインターフェース
#mydestination = $myhostname, localhost.$mydomain, localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
コメントアウトを入れ替える 受信を許可する宛先ドメイン名
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain コメントを外す 受信を許可する宛先ドメイン名
mynetworks_style = host コメントを外す 送信を許可するクライアントの範囲
relay_domains = $mydestination コメントを外す メールをリレーする宛先ドメイン名
home_mailbox = Maildir/ コメントを外す メールボックスのパス(Maildir方式を選択する)
smtpd_banner = $myhostname ESMTP unknown 追加する 応答バナーに含む内容
smtpd_etrn_restrictions = reject 追加する ETRN コマンドの無効化
smtpd_helo_required = yes 追加する HELO/EHLO コマンドの必須化(スパムメールの抑制)
smtpd_helo_restrictions = permit_mynetworks, reject_unknown_hostname 追加する HELO/EHLO コマンドのホスト名の条件(スパムメールの抑制)(左側から順にチェックされる)
smtpd_sasl_auth_enable = yes 追加する SMTPサーバのSASL認証の有効化
smtpd_sasl_type = dovecot 追加する SMTPサーバで使用するSASL認証の種類
smtpd_sasl_path = private/auth 追加する SASL認証デーモンのソケットファイル(/var/spool/postfix からの相対パスを指定する)
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client, permit 追加する SMTPサーバに接続可能なクライアントの条件(左側から順にチェックされる)
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination 追加する SMTPサーバが受信するメールの条件(左側から順にチェックされる)
smtpd_recipient_limit = 100 追加する SMTPサーバが受信するメールの同時配信数の上限(デフォルト: 1000)
mailbox_size_limit = 1000000000 追加する メールボックスサイズの上限(デフォルト:51200000バイト)
message_size_limit = 10240000 追加する 受信するメールメッセージサイズの上限(デフォルト:10240000バイト)
disable_vrfy_command = yes 追加する VRFYコマンドの無効化
3.saslauthdの自動起動設定

saslauthd はCyrus-SASLのデーモンですので、Dovecot SASLを使用する場合には必要ありません。自動起動しない設定にしておきます。

[root ~]# chkconfig --list saslauthd
saslauthd       0:off   1:off   2:off   3:off   4:off   5:off   6:off
4.saslauthdの停止

saslauthd が起動している場合には停止します。

[root ~]# service saslauthd stop
saslauthd を停止中:                                        [  OK  ]
5.Postfixの自動起動設定
[root ~]# chkconfig --list postfix
postfix         0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root ~]# chkconfig postfix on
[root ~]# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
6.Dovecotのインストール
[root ~]# yum install dovecot
(略)
Installed:
  dovecot.i386 0:1.0.7-7.el5_7.1

Complete!
7.Dovecotの設定
[root ~]# vim /etc/dovecot.conf
パラメータ 操作 設定内容の説明
protocols = pop3 追加 MUAとの間で使用するプロトコル
log_path = /var/log/dovecot.log 追加 ログファイルのパス
log_timestamp = “%Y-%m-%d %H:%M:%S “ 追加 ログの日時表示形式
login_process_per_connection = no 追加 接続毎の別プロセス割り当て
mail_location = maildir:~/Maildir 追加 メールの格納場所
postmaster_address = postmaster@goofoo.jp 変更 バウンスメールの送信先メールアドレス
auth default {
mechanisms = cram-md5
}
passdb passwd-file {
args = /etc/dovecot.passwd
}
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
}
変更 認証方式
8.メールユーザのメールディレクトリ・スケルトンの作成

新しくユーザが作成されたときに、Maildir形式のディレクトリが作成されるように、スケルトンとなるディレクトリ構造を作成しておきます。

[root ~]# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
[root ~]# chmod -R 700 /etc/skel/Maildir/
9.メールユーザ・パスワードファイルの作成
[root ~]# touch /etc/dovecot.passwd
10.メールユーザの作成

ユーザを作成して、CRAM-MD5のパスワードを生成します。そのパスワードに対して作成したユーザを対応させるように記述します。

[root ~]# useradd -m ユーザ名
[root ~]# dovecotpw -s CRAM-MD5 > /etc/dovecot.passwd
Enter new password:
Retype new password:
[root ~]# vim /etc/dovecot.passwd
ユーザ名:{CRAM-MD5}123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0
11.Dovecotの自動起動設定
[root ~]# chkconfig --list dovecot
dovecot         0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root ~]# chkconfig dovecot on
[root ~]# chkconfig --list dovecot
dovecot         0:off   1:off   2:on    3:on    4:on    5:on    6:off
12.Dovecotの起動
[root ~]# service dovecot start
Dovecot Imap を起動中:                                     [  OK  ]
13.Postfixの起動
[root ~]# service postfix start
postfix を起動中:                                          [  OK  ]
14.iptablesの設定

TCPの25(SMTP)、110(POP3)のポートを開けます。
ちなみに、imapを使う場合には143を開けます。

[root ~]# vim /etc/sysconfig/iptables
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -d 183.181.30.79 --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -d 183.181.30.79 --dport 110 -j ACCEPT
[root ~]# service iptables restart
ファイアウォールルールを適用中:                            [  OK  ]
チェインポリシーを ACCEPT に設定中mangle filter nat        [  OK  ]
iptables モジュールを取り外し中                            [  OK  ]
iptables ファイアウォールルールを適用中:                   [  OK  ]

これで、セットアップは完了です。
/var/log/mail.log と /var/log/davocet.log にエラーメッセージが出力されていないことを確認してください。

Comments are closed.