Postfix Dovecot インストール


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

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

#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 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
ヒント
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設定
[root@centos ~]# vi /usr/lib/sasl2/smtpd.conf ←32bitの場合
[root@centos ~]# vi /usr/lib64/sasl2/smtpd.conf ←64bitの場合
pwcheck_method: saslauthd
↓
pwcheck_method: auxprop ←変更
ヒント
SMTP AUTHとは(SMTP Authentication) メール転送時にSMTPサーバに対するユーザー認証を行います。
SMTP AUTHユーザー追加
[root@centos ~]# saslpasswd2 -c -u centos.orz user_name
Password: user_pass ←パスワード入力(SMTP AUTH認証用)
Again (for verification): user_pass ←パスワード再入力
[root@centos ~]# sasldblistusers2 ←メールユーザー確認
user_name@centos.orz: userPassword
ヒント
「saslpasswd2 -c -u ドメイン名(realm) ユーザー名」でユーザーを追加します。 ドメイン名(realm) は、main.cfで設定した$myoriginと同一にしてください。 「-d」オプションでユーザーを削除します。(例:saslpasswd2 -d -u centos.orz user_name) 「sasldblistusers2」でユーザーを確認します。
/etc/sasldb2所有権変更
[root@centos ~]# chgrp postfix /etc/sasldb2
[root@centos ~]# chmod 640 /etc/sasldb2
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@centos.orz ←最終行に追加(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 centos.orz ESMTP Postfix
EHLO localhost
250-centos.orz
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パスワード")
メール送信テスト
[root@centos ~]# echo test|mail user_name
[root@centos ~]# ls /home/user_name/Maildir/new
1271581750.5214_0.centos.centos.orz
[root@centos ~]# rm -f /home/user_name/Maildir/new/* ←削除
Outlook Expressの設定(POPの場合)

1.上部メニューから「ツール」>「アカウント」をクリック。

2.「追加」>「メール」をクリック。

3.「表示名」を入力して「次へ」をクリック。

4.「電子メールアドレス」を入力して「次へ」をクリック。

5.「受信メールサーバーの種類」から「POP3」を選択。
「受信メールサーバー」「送信メールサーバー」にサーバーのホスト名またはIPアドレスを入力して「次へ」をクリック。

6.アカウント名とパスワードを入力して「次へ」をクリック。

7.「完了」をクリック。

8.アカウントを選択して「プロパティ」をクリック。

9.サーバータブを開き「このサーバーは認証が必要」にチェックを入れて「OK」をクリック。

10.「閉じる」をクリック。
Outlook Expressの設定(IMAPの場合)

1.上部メニューから「ツール」>「アカウント」をクリック。

2.「追加」>「メール」をクリック。

3.「表示名」を入力して「次へ」をクリック。

4.「電子メールアドレス」を入力して「次へ」をクリック。

5.「受信メールサーバーの種類」から「IMAP」を選択。
「受信メールサーバー」「送信メールサーバー」にサーバーのホスト名またはIPアドレスを入力して「次へ」をクリック。

6.アカウント名とパスワードを入力して「次へ」をクリック。

7.「完了」をクリック。

8.アカウントを選択して「プロパティ」をクリック。

9.サーバータブを開き「このサーバーは認証が必要」にチェックを入れて「OK」をクリック。

10.「閉じる」をクリック。

11.「はい」をクリック。

12.「OK」をクリック。
不正中継テスト

1.第三者中継チェック RBL.JP へアクセス。
「ホスト名」にサーバーのホスト名を入力して「Check」ボタンをクリック。

2.「no relays accepted.」と表示されたら問題なし。
ヒント
有名な不正中継チェックサイト http://www.abuse.net/relay.html http://www.antispam-ufrj.pads.ufrj.br
外部に公開する場合
プロトコル(TCP)ポート25番(SMTP)を開放。 プロトコル(TCP)ポート110番(POP3)を開放。 プロトコル(TCP)ポート143番(IMAP)を開放。
Home PageTop