SESで30万通のテストメールを送信、発生したエラーや遅延を調査してみた

Amazon SESで 不特定多数の宛先にメールを送信する場合、十分なウォームアップと、配信制限(バウンス)に加え、予兆となる配信遅延についても、見逃さないようにしてご利用ください。
2024.03.12

Amazon SES、 Gmail 宛に 1日 1万通規模のメール送信に利用できる事を確かめるため、 約1ヶ月かけて 30万通のテストメールの送信を実施。 その送信結果の確認を試みる機会がありましたので、紹介させて頂きます。

SESの設定

認証

  • Easy DKIM、カスタム MAIL FROM ドメインを設定しました。

SES認証

  • DMARC関連設定も実施しました。

DMARC設定状況

設定セット

  • IPプールはデフォルトとしました。
  • Virtual Deliverability Managerは有効化しました。

SES設定セット

  • 全てのログをFirehose経由で保存しました

SESイベント送信先

SESのログをイベント種別毎に分類して保存するFirehoseをCloudFormationで作成してみた

メール送信

StepFunctions と EventBridege を利用した仕組みを利用しました。

Gmailが提示するメール送信者のガイドラインに則り、メール送信数を段階的に増やし、 送信先のメールアドレスと発信間隔を段階的に調整し、最終的な送信先は19。1日あたり約1.3万通のメールをSESから送信しました。

CloudWatch-SES-send

  • メール送信先の内訳
    • Gmail (@gmail.com) : 14
    • Gmail (独自ドメイン) : 1
    • Yahooメール (@ymail.ne.jp) : 1
    • Outlook (@outlook.jp) : 1
    • Cloudflare (独自ドメイン(Email Routing)) : 1
    • Amazon SES (Eメール受信): 1

結果確認

SESダッシュボード、Virtual Deliverability Manager、ログ解析を実施、メールの送信結果を確認しました。

SESダッシュボード

SESのダッシュボードを利用して、当日分のメール送信結果を確認しました。

アカウントダッシュボード

アカウントダッシュボードでは、メールの送信数、送信クォーター、拒否数、バウンス数、苦情数を確認できます。

アカウントダッシュボード

バウンスグラフの対象は、ハードバウンス数。

今回の検証中、ハードバウンスの発生率(Reputation.BounceRate)は0%でした。

ハードバウンスレート

評判メトリクス

評判メトリクス

Virtual Deliverability Manager

グラフ表示、30日前から前日分まで、日時実績数が確認できました。

Virtual Deliverability Manager ダッシュボード

2/21〜24にかけて、一時的なバウンスが記録されていました。

一時的なバウンス

ISP

ISPは「hotmail」、マイクロソフト宛に送信されたメールで一時的なバウンスが発生していました。

ISP一覧

メッセージ

配信イベント「一時的なバウンス」で絞り込みを実施、該当するメッセージを確認しました。

メッセージ

「詳細を表示」より、バウンスの原因を確認。 spamhaus のフィルタにより、SESのIPアドレス(23.251.234.2)が SPAMとして判定されていました。

一時バウンスメールのメッセージ詳細

  • 診断コード
smtp; 550 5.7.1 Service unavailable, Client host [23.251.234.2] blocked using Spamhaus. To request removal from this list see https://www.spamhaus.org/query/ip/23.251.234.2 (AS3130). [DM6NAM12FT022.eop-nam12.prod.protection.outlook.com 2024-**-**T22:06:14.295Z 08DC2D99998A2478]

ログ調査

SESのイベントをFirehose経由でイベント種別にS3に保存したログを対象に、

  • Bounce
  • DeliveryDelay

に該当するイベントの確認を試みました。

イベント種別保存のS3

Bounce

Bounce調査1

Virtual Deliverability Manager で確認した内容と同じ、Outlook宛で発生した 一時的なバウンスを確認できました。

diagnosticcode=smtp; 550 5.7.1 Service unavailable, Client host [23.251.234.5] blocked using Spamhaus. To request removal from this list see https://www.spamhaus.org/query/ip/23.251.234.5 (AS3130). [AM0EUR02FT020.eop-EUR02.prod.protection.outlook.com

Athenaを利用して集計を実施、 1日あたりのバウンス数と、@outlook のドメイン宛の正常送信数を求めました。

バウンス数_日別

OITLOOK宛正常送信数

正常な送信数は720通。バウンスが記録された数日間、23〜90通程度のメールが不着となっていました。

DeliveryDelay

遅延のタイプとして、

  • delayType : IPFailure

IPFailure – メッセージを送信する IP アドレスは、受信者の E メールプロバイダーによってブロックまたはスロットリングされています。

Amazon Simple Email Service 開発者ガイド DeliveryDelay オブジェクト

受信側メッセージ転送エージェント (MTA) によって提供される診断コードより、送信レート制限に抵触したメールが記録されていました。

  • diagnosticCode: smtp; 421-4.7.28

Gmail has detected an unusual rate of unsolicited mail. To protect our users from spam, mail has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.

Gmail SMTP errors and codes

  "deliveryDelay": {
    "timestamp": "2024-03-**T02:13:38.130Z",
    "delayType": "IPFailure",
    "reportingMTA": "74.125.23.27",
    "expirationTime": "2024-03-**T16:03:49.338Z",
    "delayedRecipients": [
      {
        "emailAddress": "****@gmail.com",
        "status": "4.7.28",
        "diagnosticCode": "smtp; 421-4.7.28 Gmail has detected an unusual rate of unsolicited mail originating\n421-4.7.28 from your SPF domain [***.***.***      35]. To protect our\n421-4.7.28 users from spam, mail sent from your domain has been temporarily\n421-4.7.28 rate limited. For more information, go to\n421-4.7.28  https://support.google.com/mail/?p=UnsolicitedRateLimitError to\n421 4.7.28 review our Bulk Email Senders Guidelines. r25-20020a63fc59000000b005dc15e82c4fsi2376511pgk.170 - gsmtp"
      }
    ]
  }

配送先のGmailにメールは到着していましたが、約100分の遅延が記録されていました。

遅延メール(6289秒)

Virtual Deliverability Manager を利用して、遅延したメールのメッセージIDに該当するメールを抽出を試みました。

遅延メッセージ確認

11:03 に送信されたメールが、12:48 に配信されていた事を確認できました。

遅延メッセージ情報

費用確認(1日分)

今回、約13000通のメールを送信した1日あたりのAWS費用は以下の通りでした。

  • Amazon SES: $2.41
  • Step Functions: $0.03
  • Firehose: $0.01

SES1日費用

まとめ

Amazon SES、ハードバウンス率 (Reputation.BounceRate) は 2%以下の利用が推奨、 バウンス率が10%に達すると、問題が解消するまでSESの一時中断措置が取られる場合がありますが、 今回の検証中、ハードバウンスを引き起こす事なく3万通のメールを送信することができました。

ただ、割合はごく小規模(0.01%台)でしたが、一時的なバウンス(ソフトバウンス)、遅延(deliveryDelay)の発生が認められました。

Amazon SESを利用して 不特定多数、一定規模以上のメールを送信を送信する場合、 Virtual Deliverability Manager に加えて、 SESの イベントログ記録を有効化し、遅延の発生率や、遅延時間の監視を実現。

Gmailなどメール送信先に起因するスロットルに起因する遅延や、一時的なバウンスの発生を早期に検出、 ドメインやIPの評価(レピュテーション)を大きく損なう前に適切に対処できる仕組みを整理して利用する事をおすすめします。

メールがバウンスされ始めたり、遅延し始めたりした場合は、SMTP エラー率が低下するまで送信量を減らします。その後、再度徐々に増やします。送信量が少ないにもかかわらずバウンスや遅延が続く場合は、個々のメールを確認して問題を特定します。たとえば、空のテスト メッセージを送信して、問題がないかどうかを確認します。

Gmail メール送信者のガイドライン

また、 Outlook で発生していた一時的なバウンス、 SESのIPアドレスが SPAM と判定された原因は不明ですが、 他の利用者により 評価が落ちていたIPアドレスを共用していた可能性は、SESの専有IPアドレスで回避できる場合があります。

今回、専有IPアドレスについて評価は実施していませんが、高いメール到達率を維持する必要がある場合には、専有IPアドレス(標準、マネージド)の導入もご検討ください。

Amazon SES での専用 IP アドレス

参考

2024年3月現在の英語ページの Gmailのドキュメントでは、 SMTP エラー メッセージ の詳細な案内が反映されています。

Gmailが提示するガイドラインの違反に伴う遅延や、バウンスの発生などの原因特定に役立つ可能性があるため、これらのコードの把握と、記録されたログについて、調査可能な状態とする事をおすすめします。

Reply Code Status Code Reply Text
450 4.2.1 The user you are trying to contact is receiving mail too quickly. Please resend your message at a later time. If the user is able to receive mail at that time, your message will be delivered. For more information, go to Limits for sending & getting mail.
450 4.2.1 The user you are trying to contact is receiving mail at a rate that prevents additional messages from being delivered. Please resend your message at a later time. If the user is able to receive mail at that time, your message will be delivered. For more information, go to Limits for sending & getting mail.
450 4.2.1 Peak SMTP relay limit exceeded for this customer. This is a temporary error. For more information on SMTP relay limits, contact your administrator or go to SMTP relay service error messages.
452 4.2.2 The recipient's inbox is out of storage space. Please direct the recipient to Manage files in your Google Drive storage.
451 4.3.0 Mail server has temporarily rejected this message. Go to About SMTP error messages for more information.
451 4.3.0 Multiple destination domains per transaction is unsupported. Please try again. For more information, go to About SMTP error messages and review RFC 5321 specifications.
421 4.3.0 Temporary System Problem. Try again later. For more information, go to About SMTP error messages.
451 4.4.2 Timeout - closing connection. For more information, go to About SMTP error messages.
421 4.4.5 Server busy, try again later. For more information, go to About SMTP error messages.
451 4.5.0 SMTP protocol violation. For more information, go to About SMTP error messages and review RFC 5321 specifications.
452 4.5.3 Domain policy size per transaction exceeded, please try this recipient in a separate transaction. For more information, go to Message bounced due to a policy rule.
452 4.5.3 Your message has too many recipients. For more information regarding Google's sending limits, go to Limits for sending & getting mail.
421 4.7.0 Connection expired, try reconnecting. For more information, go to About SMTP error messages.
421 4.7.0 IP not in whitelist for RCPT domain, closing connection. For more information, go to Allowlists, denylists, and approved senders.
421 4.7.0 Try again later, closing connection. (command) For more information, go to About SMTP error messages.
421 4.7.0 The IP address sending this message does not have a PTR record, or the corresponding forward DNS entry does not point to the sending IP. To protect our users from spam, mail sent from your IP address has been temporarily rate limited. For more information, go to Email sender guidelines.
454 4.7.0 Too many login attempts, please try again later. For more information, go to Add Gmail to another email client.
454 4.7.0 Cannot authenticate due to a temporary system problem. Try again later. For more information, go to About SMTP error messages.
421 4.7.0 TLS required for RCPT domain, closing connection. For more information, go to Email encryption in transit.
421 4.7.0 This message is suspicious due to the very low reputation of the sending IP address. To protect our users from spam, mail sent from your IP address has been temporarily rate limited. For more information, go to Why has Gmail blocked my messages?.
421 4.7.0 This message is suspicious due to the very low reputation of the sending domain. To best protect our users from spam, the message has been blocked. For more information, go to Why has Gmail blocked my messages?.
421 4.7.0 This message is suspicious due to the nature of the content or the links within. To best protect our users from spam, the message has been blocked. For more information, go to Why has Gmail blocked my messages?.
451 4.7.24 The SPF record of the sending domain has one or more suspicious entries. To protect our users from spam, mail sent from your IP address has been temporarily rate limited. For more information, go to Email sender guidelines.
451 4.7.26 Unauthenticated email from domain-name is not accepted due to domain's DMARC policy, but temporary DNS failures prevent authentication. Please contact the administrator of domain-name domain if this was a legitimate mail. To learn about the DMARC initiative, go to Gmail Help.
421 4.7.26 This mail has been rate limited because it is unauthenticated. Gmail requires all senders to authenticate with either SPF or DKIM. Authentication results: DKIM = did not pass SPF domain-name with ip: ip-address = did not pass. To resolve this issue, go to Email sender guidelines.
421 4.7.27 This mail has been rate limited because SPF does not pass. Gmail requires all large senders to authenticate with SPF. Authentication results: SPF domain-name with ip: ip-address = did not pass. To resolve this issue, go to Define your SPF record—Basic setup.
421 4.7.28 This mail has been rate limited because DKIM does not pass. Gmail requires all large senders to authenticate with DKIM. Authentication results: DKIM = did not pass. For instructions on setting up DKIM authentication, go to Turn on DKIM for your domain.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail. To protect our users from spam, mail has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail originating from your IP address ip-address. To protect our users from spam, mail sent from your IP address has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail originating from your IP Netblock ip-address. To protect our users from spam, mail sent from your IP Netblock has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail originating from your DKIM domain domain-name. To protect our users from spam, mail sent from your domain has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail originating from your SPF domain domain-name. To protect our users from spam, mail sent from your domain has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual rate of unsolicited mail containing one of your URL domains. To protect our users from spam, mail with the URL has been temporarily rate limited. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 Gmail has detected an unusual amount of unsolicited mail originating from your IP address. To protect our users from spam, mail sent from your IP address has been temporarily blocked. To review our bulk email senders guidelines, go to Email sender guidelines.
421 4.7.28 GMail has detected this message exceeded its quota for sending messages with the same Message-ID:. To best protect our users, the message has been temporarily rejected. For more information, go to Why has Gmail blocked my messages?.
421 4.7.29 This mail has been rate limited because TLS wasn't used. Gmail requires all large senders to use TLS/SSL during SMTP. For instructions on using TLS, go to TLS & SSL connections.

Gmail SMTP errors and codes