Postfix から Amazon SES へリレーするときの注意点

Posted on

今回も AWS ネタです。 Postfix から Amazon SES へリレーして送信するようにしていたのですが、cron からのメールが届いていないことに気づきました。 maillog を見てみると "554 Message rejected: Email address is not verified." というエラーでバウンスしていました。

Postfix の設定はドキュメントどおりです。 Verified Sender でドメインの認証は済んでいるし、アプリからのメールは問題なくリレーできています。

おかしいなと思いましたが、ログを遡るとすぐに原因がわかりました。

Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/pickup[27539]: 24B8962BA2: uid=0 from=<root>
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/cleanup[27755]: 24B8962BA2: message-id=<20140405185012.24B8962BA2@web.localdomain>
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/qmgr[18606]: 24B8962BA2: from=<root@web.localdomain>, size=698, nrcpt=1 (queue active)
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/cleanup[27755]: 816B662BA1: message-id=<20140405185012.24B8962BA2@web.localdomain>
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/qmgr[18606]: 816B662BA1: from=<root@web.localdomain>, size=829, nrcpt=1 (queue active)
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/local[27757]: 24B8962BA2: to=<root@web.localdomain>, orig_to=<root>, relay=local, delay=0.49, delays=0.29/0.19/0/0.01, dsn=2.0.0, status=sent (forwarded as 816B662BA1)
Apr  6 03:50:12 ip-xx-xx-xx-xx postfix/qmgr[18606]: 24B8962BA2: removed
Apr  6 03:50:14 ip-xx-xx-xx-xx postfix/smtp[27758]: 816B662BA1: to=<xxxxxx@xxxxxx.xx>, orig_to=<root>, relay=email-smtp.us-west-2.amazonaws.com[54.213.255.181]:25, delay=1.6, delays=0.01/0.15/0.89/0.53, dsn=5.0.0, status=bounced (host email-smtp.us-west-2.amazonaws.com[54.213.255.181] said: 554 Message rejected: Email address is not verified. (in reply to end of DATA command))

From が root@web.localdomain になっていて、Verified Sender で登録したドメインと一致していないために SES から弾かれていました。

このサーバのホスト名は web で、gethostname() で FQDN が取得できないので mydomain から localdomain が補完されています。

Postfix の myhostname を設定する

/etc/postfix/main.cf の myhostname に Verified Sender で登録したドメインを設定すれば解決します。

myhostname = manabusakai.com

myhostname のデフォルト値は gethostname() から FQDN を取得するため、サーバのホスト名が Verified Sender で登録したドメインと違うのであれば正しく設定する必要があります。

Postfix のデフォルト値は postconf -d で確認できます。

$ postconf -d | grep ^myhostname
myhostname = web.localdomain

Popular Entries

Recent Entries