Postfixを利用したSMTPリレーサーバーの導入で旬について記載しています。
※AWS SESの設定についてはこちらを参照してください
1.postfixのインストール。
次のコマンドを実行します。
yum -y install postfix
実行結果
読み込んだプラグイン:priorities, update-motd, upgrade-helper amzn-main | 2.1 kB 00:00 amzn-updates | 2.5 kB 00:00 依存性の解決をしています --> トランザクションの確認を実行しています。 ---> パッケージ postfix.x86_64 2:2.6.6-2.15.amzn1 を インストール --> 依存性の処理をしています: postgresql-libs のパッケージ: 2:postfix-2.6.6-2.15.amzn1.x86_64 --> 依存性の処理をしています: mysql-libs のパッケージ: 2:postfix-2.6.6-2.15.amzn1.x86_64 --> 依存性の処理をしています: libmysqlclient.so.18(libmysqlclient_16)(64bit) の パッケージ: 2:postfix-2.6.6-2.15.amzn1.x86_64 --> 依存性の処理をしています: libpq.so.5()(64bit) のパッケージ: 2:postfix-2.6.6-2.15.amzn1.x86_64 --> 依存性の処理をしています: libmysqlclient.so.18()(64bit) のパッケージ: 2:postfix-2.6.6-2.15.amzn1.x86_64 --> トランザクションの確認を実行しています。 ---> パッケージ mysql55-libs.x86_64 0:5.5.57-1.18.amzn1 を インストール ---> パッケージ postgresql92-libs.x86_64 0:9.2.22-1.61.amzn1 を インストール --> 依存性解決を終了しました。 依存性を解決しました ================================================================================ Package アーキテクチャー バージョン リポジトリー 容量 ================================================================================ インストール中: postfix x86_64 2:2.6.6-2.15.amzn1 amzn-main 4.1 M 依存性関連でのインストールをします: mysql55-libs x86_64 5.5.57-1.18.amzn1 amzn-main 816 k postgresql92-libs x86_64 9.2.22-1.61.amzn1 amzn-main 262 k トランザクションの要約 ================================================================================ インストール 1 パッケージ (+2 個の依存関係のパッケージ) 総ダウンロード容量: 5.2 M インストール容量: 13 M Downloading packages: (1/3): mysql55-libs-5.5.57-1.18.amzn1.x86_64.rpm | 816 kB 00:00 (2/3): postgresql92-libs-9.2.22-1.61.amzn1.x86_64.rpm | 262 kB 00:00 (3/3): postfix-2.6.6-2.15.amzn1.x86_64.rpm | 4.1 MB 00:00 -------------------------------------------------------------------------------- 合計 8.5 MB/s | 5.2 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : mysql55-libs-5.5.57-1.18.amzn1.x86_64 1/3 インストール中 : postgresql92-libs-9.2.22-1.61.amzn1.x86_64 2/3 インストール中 : 2:postfix-2.6.6-2.15.amzn1.x86_64 3/3 検証中 : postgresql92-libs-9.2.22-1.61.amzn1.x86_64 1/3 検証中 : 2:postfix-2.6.6-2.15.amzn1.x86_64 2/3 検証中 : mysql55-libs-5.5.57-1.18.amzn1.x86_64 3/3 インストール: postfix.x86_64 2:2.6.6-2.15.amzn1 依存性関連をインストールしました: mysql55-libs.x86_64 0:5.5.57-1.18.amzn1 postgresql92-libs.x86_64 0:9.2.22-1.61.amzn1 完了しました!
2.インストール後の確認
次のコマンドを実行します。
postconf | grep mail_version
実行結果
mail_version = 2.6.6 milter_macro_v = $mail_name $mail_version
3.プラグインの追加
「cyrus-sasl-plain」を追加します
次のコマンドを実行します。
yum install -y cyrus-sasl-plain
実行結果
読み込んだプラグイン:priorities, update-motd, upgrade-helper パッケージ cyrus-sasl-plain-2.1.23-13.16.amzn1.x86_64 はインストール済みか最新バージョンです 何もしません
※執筆時のAmazon Linux環境ではインストール済みでした。
1.「main.cf」を設定します。
次のコマンドを実行します。
vi /etc/postfix/main.cf
実行結果
# of all parameters. For the syntax, and for a complete parameter # list, see the postconf(5) manual page (command: "man 5 postconf"). # ....省略 # readme_directory: The location of the Postfix README files. # readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
ファイルの最後に次の値を追加し保存します。
relayhost = email-smtp.us-west-2.amazonaws.com:587 smtp_sasl_auth_enable = yes smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_use_tls = yes smtp_tls_security_level = encrypt smtp_tls_note_starttls_offer = yes smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt smtp_tls_loglevel = 1
2.「master.cf」を設定します。
次のコマンドを実行します。
vi /etc/postfix/master.cf
実行結果
#
# Postfix master process configuration file. For details on the format
# of the file, see the master(5) manual page (command: “man 5 master”).
#
# Do not forget to execute “postfix reload” after editing this file.
#
# ==========================================================================
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n – n – – smtpd
….省略
smtp unix – – n – – smtp
# When relaying mail as backup MX, disable fallback_relay to avoid MX loops
relay unix – – n – – smtp
-o smtp_fallback_relay=
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq unix n – n – – showq
….以下省略
次の値に修正して保存します。
relay unix – – n – – smtp
# -o smtp_fallback_relay=
# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
3.「sasl_passwd」を設定します。
次のコマンドを実行します。
vi /etc/postfix/sasl_passwd
新規にファイルが作成されます。
※"/etc/postfix/sasl_passwd" [New File]
新規ファイルに次の値を追加し保存します。
email-smtp.us-west-2.amazonaws.com:587 [Smtp Username]: [Smtp Password]
※IAMで作成したユーザーの[Smtp Username][Smtp Password]を入力します。
4.SMTP 認証情報を含む hashmap データベースファイルを作成します。
次のコマンドを実行します。
postmap hash:/etc/postfix/sasl_passwd
実行結果
#
5.所有者をルートに変更します。
次のコマンドを実行します。
sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
実行結果
#
6.ファイルへのアクセスを制限します。
次のコマンドを実行します。
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
実行結果
#
7.PostfixにCA証明書の場所を認識させます。
次のコマンドを実行します。
sudo postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt'
実行結果
#
8.OS起動時に自動的にサービスも起動するように設定をします。
次のコマンドを実行します。
chkconfig postfix on
実行結果
#
9.サービスを再起動します。
次のコマンドを実行します。
/etc/rc.d/init.d/postfix start
実行結果
postfix を起動中: [ OK ]
次のコマンドを実行します。
sendmail -f mail@example.com mail@example.com From: mail@example.com Subject: Postfix Send Mail Test - Server01 This email was sent through Amazon SES! .
※mail@example.comを修正してください。
以下のコマンドを実行します。
tail -n10 /vat/log/maillog
実行結果
Jan 01 00:00:00 ip-xxx-xxx-xxx-xxx postfix/smtp[11161]: 0010360A01: to=, relay=email-smtp.us-west-2.amazonaws.com[xxx.xxx.xxx.xxx]:587, delay=1.8, delays=0.05/0.03/1/0.7, dsn=2.0.0, status=sent (250 Ok 010101500aca038e-00a6ffe9-5177-4626-bbae-e00022bec011-000000)
「status=sent」となっていれば送信されています。
特定のログのみ確認したい場合は、次のコマンドのように実行します。
例)直近10件のログから送信が成功しているログを表示。
tail -n10 /vat/log/maillog | grep status=sent