Postfix Dovecot インストール

Postfixインストール
[root@centos ~]# yum -y install postfix
Postfix設定
[root@centos ~]# vi /etc/postfix/main.cf
#myhostname = host.domain.tld
↓
myhostname = mail.server-manual.com ←コメント解除&変更(ホスト名をFQDNで指定)

#mydomain = domain.tld
↓
mydomain = server-manual.com ←コメント解除&変更(ドメイン名を指定)

#myorigin = $mydomain
↓
myorigin = $mydomain ←コメント解除(送信元メール@以降)

inet_interfaces = localhost
↓
inet_interfaces = all ←変更(受信するネットワークアドレスを指定)

mydestination = $myhostname, localhost.$mydomain, localhost
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ←変更(ローカル配送先)

#relay_domains = $mydestination
↓
relay_domains = $mydestination ←コメント解除(リレーを許可するドメインを指定)

#home_mailbox = Maildir/
↓
home_mailbox = Maildir/ ←コメント解除(Maildir形式)

#mailbox_command = /some/where/procmail
↓
mailbox_command = /usr/bin/procmail ←コメント解除&変更(procmailのパスを指定)
cyrus-sasl インストール
[root@centos ~]# yum -y install cyrus-sasl
[root@centos ~]# /etc/rc.d/init.d/ saslauthd start
[root@centos ~]# chkconfig saslauthd on
[root@centos ~]# chkconfig --list saslauthd
saslauthd         0:off   1:off   2:on    3:on    4:on    5:on    6:off
ヒント
SMTP AUTHは(SMTP Authentication) メール転送時にSMTPサーバに対するユーザー認証を行います。
Postfix設定 (専用ユーザーでSMTP認証する場合)
[root@centos ~]# vi /etc/postfix/main.cf
↓最終行に下記を記入
# Cyrus-SASL configuration
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
[root@centos ~]# vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd
↓
pwcheck_method: auxprop ←変更
ヒント
smtpd_sasl_auth_enable = yes ←SASLによるSMTP-Authを許可する smtpd_sasl_local_domain = $mydomain ←リレーを許可する smtpd_sasl_security_options = noanonymous ←匿名ログインを許可しない smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination ←リレー許可を設定 broken_sasl_auth_clients = yes ←AUTHコマンドを認識できないメールソフトに対応させる
SMTP AUTHユーザー追加 (専用ユーザーでSMTP認証する場合)
[root@centos ~]# saslpasswd2 -u server-manual.com -c mail@server-manual.com
Password: user_pass ←パスワード入力(SMTP AUTH認証用)
Again (for verification): user_pass ←パスワード再入力
[root@centos ~]# sasldblistusers2 ←メールユーザー確認
mail@server-manual.com: userPassword
[root@centos ~]# chgrp postfix /etc/sasldb2
[root@centos ~]# chmod 640 /etc/sasldb2
ヒント
「saslpasswd2 -u ドメイン名(realm) -c ユーザー名」でユーザーを追加します。 ドメイン名(realm) は、main.cfで設定した$myoriginと同一にしてください。 「-d」オプションでユーザーを削除します。(例:saslpasswd2 -d -u server-manual.com user_name) 「sasldblistusers2」でユーザーを確認します。
sendmail停止
[root@centos ~]# /etc/rc.d/init.d/sendmail stop
[root@centos ~]# chkconfig sendmail off
[root@centos ~]# alternatives --config mta
2 プログラムがあり 'mta'を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Enterを押して現在の選択[+]を保持するか、選択番号を入力します:2 ←2(postfix)を入力してエンター
Postfix起動
[root@centos ~]# /etc/rc.d/init.d/postfix start
[root@centos ~]# chkconfig postfix on
[root@centos ~]# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
Dovecotインストール
[root@centos ~]# yum -y install dovecot
dovecot.conf編集
[root@centos ~]# vi /etc/dovecot.conf
#protocols = imap imaps pop3 pop3s
↓
protocols = imap pop3 ←コメント解除&変更(imap pop3に対応)

#mail_location =
↓
mail_location = maildir:~/Maildir ←コメント解除&変更(Maildir形式)
dovecot起動
[root@centos ~]# /etc/rc.d/init.d/dovecot start
[root@centos ~]# chkconfig dovecot on
[root@centos ~]# chkconfig --list dovecot
dovecot         0:off   1:off   2:on    3:on    4:on    5:on    6:off
メールエイリアスのデータベース再構築
[root@centos ~]# vi /etc/aliases
root:		user_name@server-manual.com ←最終行に追加(root宛のメールを転送)
[root@centos ~]# postalias /etc/aliases ←設定を反映
既存ユーザー用メールディレクトリ作成
[root@centos ~]# mkdir -p /home/user_name/Maildir/{cur,new,tmp}
[root@centos ~]# chmod -R 700 /home/user_name/Maildir
[root@centos ~]# chown -R user_name:user_name /home/user_name/Maildir
追加ユーザー用メールディレクトリ作成
[root@centos ~]# mkdir -p /etc/skel/Maildir/{cur,new,tmp}
[root@centos ~]# chmod -R 700 /etc/skel/Maildir/
procmail設定
[root@centos ~]# vi /etc/procmailrc
↓下記を記入
SHELL=/bin/bash
PATH=/bin:/usr/bin
DROPPRIVS=yes
MAILDIR=$HOME/Maildir
DEFAULT=$MAILDIR/
LOGFILE=$MAILDIR/procmail.log

# 件名に「未承諾広告※」を含むメールを破棄
:0
* ^Subject:.*iso-2022-jp
* ^Subject:\/.*
* ? echo "$MATCH" | nkf -mwZ2 | sed 's/[[:space:]]//g' | egrep '未承諾広告※'
/dev/null
Procmailログローテーション
[root@centos ~]# vi /etc/logrotate.d/procmail
/home/*/Maildir/procmail.log {
    missingok
    nocreate
    notifempty
}
POP3接続確認
[root@centos ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
USER user_name
+OK
PASS user_pass
+OK Logged in.
LIST
+OK 0 messages:
.
QUIT
+OK Logging out.
Connection closed by foreign host.
BASE64エンコードでパスワード作成
[root@centos ~]# perl -MMIME::Base64 -e 'print encode_base64("user_name\0user_name\0user_pass");'
dXNlcl9uYW1lAHVzZXJfbmFtZQB1c2VyX3Bhc3M=
SMTP接続確認
[root@centos ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 server-manual.com ESMTP Postfix
EHLO localhost
250-server-manual.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
AUTH PLAIN dXNlcl9uYW1lAHVzZXJfbmFtZQB1c2VyX3Bhc3M=
235 2.0.0 Authentication successful
QUIT
221 2.0.0 Bye
Connection closed by foreign host.
ヒント
encode_base64()の書式は encode_base64("ユーザー名\0ユーザー名\0パスワード")
不正中継テスト
1.http://www.antispam-ufrj.pads.ufrj.br/test-relay.html へアクセス。
2.「FQDN」を入力して「test」ボタンをクリック。
3.「All tests performed, no relays accepted by remote host.」と表示されたら問題なし。
外部に公開する場合
プロトコル(TCP)ポート25番(SMTP)を開放。 プロトコル(TCP)ポート110番(POP3)を開放。 プロトコル(TCP)ポート143番(IMAP)を開放。
Home PageTop