** 環境 [#e9d9a626]

- さくらのVPS
- CentOS 6.8

** 前提条件 [#d66e7f27]

- 独自ドメイン (example.com 等) 取得済み
- mail.example.com の A レコードの値がサーバーの GIP に設定済み
- mail.example.com の MX レコード設定済み

** iptables 設定 [#n33b1e0b]

 $ sudo vi /etc/sysconfig/iptables

 -A SERVICES -p tcp --dport 25 -j ACCEPT
 -A SERVICES -p tcp --dport 587 -j ACCEPT
 -A SERVICES -p tcp --dport 465 -j ACCEPT
 -A SERVICES -p tcp --dport 110 -j ACCEPT
 -A SERVICES -p tcp --dport 995 -j ACCEPT
 -A SERVICES -p tcp --dport 143 -j ACCEPT
 -A SERVICES -p tcp --dport 993 -j ACCEPT

 $ sudo service iptables restart

** Postfix 構築 [#x0d0cca0]

- Postfix インストール

 $ sudo yum -y install postfix

 $ postconf  | grep mail_version
 mail_version = 2.6.6

** Poftfix 設定 [#d7901032]

*** /etc/postfix/main.cf 編集 [#v333467c]

 $ sudo vi /etc/postfix/main.cf

- myhostname 設定

 myhostname = mail.example.com

- mydomain 設定

 mydomain = example.com

- myorigin 設定

 myorigin = $mydomain

- inet_interfaces 設定

 inet_interfaces = all

- mydestination 設定

 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

- home_mailbox 設定

 home_mailbox = Maildir/

- smtpd_banner 設定

 smtpd_banner = $myhostname ESMTP unknown

- SMTP 認証設定追加

 smtpd_sasl_auth_enable = yes
 smtpd_sasl_local_domain = $myhostname
 smtpd_recipient_restrictions =
     permit_mynetworks
     permit_sasl_authenticated
     reject_unauth_destination

- 受信メールサイズ制限設定 (10MB)

 message_size_limit = 10485760

*** /etc/postfix/master.cf 編集 [#i516cdce]

 $ sudo vi /etc/postfix/master.cf

- Submission ポート有効化

 submission inet n       -       n       -       -       smtpd

- Submission ポートでの SMTP 認証有効化

 #  -o smtpd_tls_security_level=encrypt
   -o smtpd_sasl_auth_enable=yes
 #  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

**  SMTP 認証設定 (システムのユーザー/パスを SMTP 認証ユーザー/パスに利用する場合) [#p0d4a5a3]

- Cyrus SASL ライブラリ インストール (未インストールの場合)

 $ sudo yum -y install cyrus-sasl

- saslauthd 起動

 $ sudo /etc/rc.d/init.d/saslauthd start

- 自動起動設定

 $ sudo chkconfig saslauthd on

*** 新規ユーザー対処 [#q8c78712]

- 新規ユーザー追加時に Maildir 形式メールボックス自動作成設定

 $ sudo mkdir -p /etc/skel/Maildir/{new,cur,tmp}

 $ sudo chmod -R 700 /etc/skel/Maildir/

*** unknown ユーザー宛メールの廃棄設定 [#k6fcf7fe]

 $ sudo vi /etc/postfix/main.cf

- 最終行に unknown_user への転送設定を追記

 local_recipient_maps =
 luser_relay = unknown_user@localhost

 $ su -
 # echo unknown_user: /dev/null >> /etc/aliases
 # newaliases
 # exit

*** Sendmail 停止 (Sendmail が稼働している場合) [#c87b1ff8]

- デフォルトの MTA を Postfix に変更

 $ sudo alternatives --config mta

- Sendmail 停止

 $ sudo service sendmail stop
 $ sudo chkconfig sendmail off

*** Postfix 起動 [#qd2057a9]

- Posftfix 再起動

 $ sudo /etc/rc.d/init.d/postfix restart

- 自動起動設定

 $ sudo chkconfig postfix on

** ユーザー作成 [#c9a12d18]

- ユーザー追加 (SSH 接続不要の場合)

 $ sudo useradd -s /sbin/nologin testuser

- パスワード設定

 $ sudo passwd testuser

- &color(red){※}; SMTP 認証用のユーザー名/パスワード設定とシステムユーザーを分ける場合は saslpasswd2 を利用する必要あり

*** メール受信確認 [#l1cc3249]

- Gmail 等から testuser@example.com 宛にメールを送信
- /home/testuser/Maildir/new/ 配下にファイル追加れていることを確認
- 追加されない場合は /var/log/maillog 等を確認

** Devecot インストール [#m4c14baf]

 $ sudo yum -y install dovecot
 $ dovecot --version
 2.0.9

** Devecot 設定 [#pec811ec]

*** /etc/dovecot/conf.d/10-mail.conf 編集 [#u589f61c]

 $ sudo vi /etc/dovecot/conf.d/10-mail.conf

- mail_location 設定

 mail_location = maildir:~/Maildir

*** /etc/dovecot/conf.d/10-auth.conf 編集 [#u1dc5513]

 $ sudo vi /etc/dovecot/conf.d/10-auth.conf

- plain text 認証を許可

 disable_plaintext_auth = no

 auth_mechanisms = plain login

*** /etc/dovecot/conf.d/10-ssl.conf 編集 [#s0c797b8]

 $ sudo vi /etc/dovecot/conf.d/10-ssl.conf

- SSL 接続を無効化

 ssl = no

** Devecot 起動 [#md74cc00]

 $ sudo /etc/rc.d/init.d/dovecot start

- 自動起動設定

 $ sudo chkconfig dovecot on

** メール送受信の確認 [#c9f94290]

- Thunderbird 等のメールクライアントにてアカウント設定しメール送受信確認
-- POP / SMTP サーバーを mail.example.com に指定
-- POP ポート番号: 110
-- SMTP ポート番号: 587
-- POP / SMTP 認証方式: 平文のパスワード認証


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS