amazon SESとpostfixを使ってメール送信

はじめに

awsSMTPが制限されているため、SESと連係してメールを送信します。

SES用のIAMユーザーを追加

  • AWS管理コンソールのSESにアクセス。リージョンを聞かれるが、TOKYOリージョンがないので、US West(Oregon)を選択する。
  • SES > SMTP Settings から [Create My SMTP Credentials] をクリック
IAM User Name : ses-smtp-user.20190101-123456
SMTP Username : 保存しておく
SMTP Password : 保存しておく

参考:
https://qiita.com/fantasista_21jp/items/e227f802095a0049a8d0

送信承認ポリシーの作成(ドメイン認証)

ドメインを認証してDKIMを設定する

  • ナビゲーションの「Identity Management」にある「Domains」を押下します。
  • 「Verify a New Domain」をクリック
  • Verify This Domain : sample.domain.com
  • Generate DKIM Settings にチェックを入れる

DNS設定

DNSレコードを登録します。

Domain Verification Record(1レコード)
DKIM Record Set(3レコード)
Email Receiving Record(1レコード)

参考:
https://www.ritolab.com/entry/72

SESの制限解除申請

サポートからSESの制限緩和のリクエストを出す。

サービス: SES 送信制限
リージョン: 米国西部(オレゴン)
制限の名前: 希望する一日あたりの送信クォータ
申請する上限数: 50000
申請理由の説明: 社内システムでメール送信する必要があるため

アカウントがサンドボックスにあるかどうかを判断は、
ナビゲーションペインで、[Email Sending (E メール送信)]、
[Sending Statistics (送信ステータス)] がlimitedになってなければOK

参考:
https://docs.aws.amazon.com/ja_jp/ses/latest/DeveloperGuide/request-production-access.html

MTAの設定

smtpの設定

smtpの設定
# vi /etc/postfix/main.cf
------------------------
#smtpd_use_tls=no
myhostname = sample
#relayhost = 

# SES
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
ca-certificates.crt
------------------------

# vi /etc/postfix/sasl_passw
[email-smtp.us-west-2.amazonaws.com]:587 SMTP ユーザー名:SMTP パスワード

hashmap データベースファイル作成
# sudo postmap hash:/etc/postfix/sasl_passwd
# sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
# sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

postfixの設定を反映
# service postfix restart

動作確認

テストメール送信 ※fromを偽装するとエラーになるので注意
#sendmail -f no-reply@sample.domain.com test@mail.com
------------------------
From: no-reply<no-reply@sample.domain.com>
Subject: Amazon SES Test
This message was sent using Amazon SES.
.
------------------------

参考
https://docs.aws.amazon.com/ja_jp/ses/latest/DeveloperGuide/postfix.html