Amazon SESのSMTPインターフェイスへセルフマネージドのMTAからSMTPリレーしている環境でバウンスの発生やAmazon SESに存在しないIDを用いた際に出力されるログを確認してみた

Amazon SESのSMTPインターフェイスへセルフマネージドのMTAからSMTPリレーしている環境でバウンスの発生やAmazon SESに存在しないIDを用いた際に出力されるログを確認してみた

バウンス通知やVirtual Deliverability Managerを有効活用しよう
2025.11.06

バウンスの発生やAmazon SESに存在しないIDでSMTPリレーを使用したときにMTA側でどんなログが出力されるか気になる

こんにちは、のんピ(@non____97)です。

皆さんはバウンスの発生やAmazon SESに存在しないIDでSMTPリレーを使用したときにMTA側でどんなログが出力されるか気になったことはありますか? 私はあります。

以下記事で紹介している通り、Amazon SESでメールを送信する際にはシークレット管理やスループット向上の関係でAPIを使用することが推奨されています。

https://dev.classmethod.jp/articles/amazon-ses-send-v1-v2/

一方、既存システムをAWS上に移行する際、システムが配送するメール送信の仕組みとしてAmazon SESのAPIを用いるのは中々レアケースではないでしょうか。

実際はAmazon SESのSMTPインターフェイスを用いて送信することが多いと思います。

この時、SMTPインターフェイスに直接メールをリレーするのではなく、PostfixなどのMTA用のサーバーを介してリレーすることが多いのかと考えます。

この時、バウンスの発生やAmazon SESに存在しないIDでSMTPリレーを使用したときにMTA側でどんなログが出力されるのでしょうか。メールアドレスが存在しない場合などでバウンスした場合にメールの送信者は特定することはできるのでしょうか。

実際に確認をしてみます。

いきなりまとめ

  • バウンスしたことはMTAのログには記録されない
    • バウンス通知やVirtual Deliverability Managerを設定し、記録されたメッセージIDとMTAのログを突き合わせることで、メールの送信元IPアドレスを特定することは可能
  • 存在しないIDのドメインを用いたリレーの試行はMTAのログに記録される

Amazon SESのSMTPインターフェイスへセルフマネージドのMTAからSMTPリレーする場合にバウンスの発生やAmazon SESに存在しないIDを用いた際にに出力されるログを確認してみた

やってみた

検証環境

検証環境は以下のとおりです。

検証環境構成図.png

Amazon SESの設定

www.non-97.netというドメインのAmazon SESのIDを作成します。こちらがメールの送信元ドメインになります。

1.IDの作成.png

Easy DKIMのレコードをDNSゾーンに登録します。しばらくしてIDステータスが検証済みになったことを確認します。

2.検証されたことを確認.png

バウンスおよび正常に配送されたことを確認するためにフィードバック転送を有効にし、指定したSNSトピックに通知をします。

3.E メールのフィードバック転送_0.png

SMTPインターフェイスを使用するためSMTPユーザーを作成します。

4.ses-smtp-user.20251020-211719.png

これでAmazon SESの設定は完了です。

Postfixの設定

続いて、MTAの設定です。

MTAとしてPostfixを使用するのでPostfixをインストールします。また、mailコマンドでメールを送信するためにmailxもインストールします。

$ sudo dnf install \
  postfix \
  mailx \
  -y
Last metadata expiration check: 0:15:48 ago on Mon Nov  3 06:03:58 2025.
Dependencies resolved.
=====================================================================================================================
 Package                Architecture          Version                               Repository                  Size
=====================================================================================================================
Installing:
 mailx                  x86_64                12.5-43.amzn2023.0.1                  amazonlinux                263 k
 postfix                x86_64                2:3.7.2-4.amzn2023.0.5                amazonlinux                1.5 M
Installing dependencies:
 libicu                 x86_64                67.1-7.amzn2023.0.4                   amazonlinux                9.6 M

Transaction Summary
=====================================================================================================================
Install  3 Packages

Total download size: 11 M
Installed size: 38 M
Downloading Packages:
(1/3): mailx-12.5-43.amzn2023.0.1.x86_64.rpm                                         5.6 MB/s | 263 kB     00:00
(2/3): postfix-3.7.2-4.amzn2023.0.5.x86_64.rpm                                        24 MB/s | 1.5 MB     00:00
(3/3): libicu-67.1-7.amzn2023.0.4.x86_64.rpm                                          60 MB/s | 9.6 MB     00:00
---------------------------------------------------------------------------------------------------------------------
Total                                                                                 57 MB/s |  11 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                             1/1
  Installing       : libicu-67.1-7.amzn2023.0.4.x86_64                                                           1/3
  Running scriptlet: postfix-2:3.7.2-4.amzn2023.0.5.x86_64                                                       2/3
  Installing       : postfix-2:3.7.2-4.amzn2023.0.5.x86_64                                                       2/3
  Running scriptlet: postfix-2:3.7.2-4.amzn2023.0.5.x86_64                                                       2/3
  Running scriptlet: mailx-12.5-43.amzn2023.0.1.x86_64                                                           3/3
  Installing       : mailx-12.5-43.amzn2023.0.1.x86_64                                                           3/3
  Running scriptlet: mailx-12.5-43.amzn2023.0.1.x86_64                                                           3/3
  Verifying        : libicu-67.1-7.amzn2023.0.4.x86_64                                                           1/3
  Verifying        : mailx-12.5-43.amzn2023.0.1.x86_64                                                           2/3
  Verifying        : postfix-2:3.7.2-4.amzn2023.0.5.x86_64                                                       3/3

Installed:
  libicu-67.1-7.amzn2023.0.4.x86_64    mailx-12.5-43.amzn2023.0.1.x86_64    postfix-2:3.7.2-4.amzn2023.0.5.x86_64

Complete!

以下記事を参考にPostfixの設定を行います。

https://dev.classmethod.jp/articles/nlb-smtp-gmail/

$ postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
compatibility_level = 3.7
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
html_directory = no
inet_interfaces = localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
meta_directory = /etc/postfix
mydestination = $myhostname, localhost.$mydomain, localhost
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix/README_FILES
sample_directory = /usr/share/doc/postfix/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
shlib_directory = /usr/lib64/postfix
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_CApath = /etc/pki/tls/certs
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
smtpd_tls_security_level = may
unknown_local_recipient_reject_code = 550

$ sudo cp -a /etc/postfix/main.cf /etc/postfix/main.cf.`date +"%Y%m%d"`

$ ls -l /etc/postfix/main.cf*
-rw-r--r--. 1 root root 29709 Jan 16  2024 /etc/postfix/main.cf
-rw-r--r--. 1 root root 29709 Jan 16  2024 /etc/postfix/main.cf.20251103
-rw-r--r--. 1 root root 29470 Jan 16  2024 /etc/postfix/main.cf.proto

$ sudo postconf -e "myhostname = internal-mta.www.non-97.net" \
"mydomain = www.non-97.net" \
"myorigin = \$mydomain" \
"inet_interfaces = all" \
"inet_protocols = ipv4" \
"mydestination = \$myhostname, localhost.\$mydomain, localhost" \
"mynetworks = 172.31.0.0/16, 127.0.0.0/8" \
"home_mailbox = Maildir/" \
"masquerade_domains = \$mydomain" \
"smtpd_banner = \$myhostname ESMTP unknown" \
"relayhost = [email-smtp.us-east-1.amazonaws.com]:587" \
"smtp_sasl_auth_enable = yes" \
"smtp_sasl_security_options = noanonymous" \
"smtp_sasl_tls_security_options = noanonymous" \
"smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" \
"smtp_sasl_mechanism_filter = digest-md5, plain" \
"smtp_use_tls = yes" \
"smtp_tls_security_level = secure" \
"smtp_tls_loglevel = 1" \
"smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt" \
"smtp_tls_note_starttls_offer = yes"

$ sudo diff -u /etc/postfix/main.cf.`date +"%Y%m%d"` /etc/postfix/main.cf
--- /etc/postfix/main.cf.20251103       2024-01-16 16:47:12.000000000 +0000
+++ /etc/postfix/main.cf        2025-11-03 12:49:34.561670695 +0000
@@ -136,10 +136,10 @@
 #inet_interfaces = all
 #inet_interfaces = $myhostname
 #inet_interfaces = $myhostname, localhost
-inet_interfaces = localhost
+inet_interfaces = all

 # Enable IPv4, and IPv6 if supported
-inet_protocols = all
+inet_protocols = ipv4

 # The proxy_interfaces parameter specifies the network interface
 # addresses that this mail system receives mail on by way of a
@@ -737,11 +737,27 @@
 # trusted to sign either remote SMTP server certificates or intermediate CA
 # certificates.
 #
-smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
+smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt

 # Use TLS if this is supported by the remote SMTP server, otherwise use
 # plaintext (opportunistic TLS outbound).
 #
-smtp_tls_security_level = may
+smtp_tls_security_level = secure
 meta_directory = /etc/postfix
 shlib_directory = /usr/lib64/postfix
+smtp_tls_loglevel = 1
+smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
+smtp_use_tls = yes
+mynetworks = 172.31.0.0/16, 127.0.0.0/8
+home_mailbox = Maildir/
+myhostname = internal-mta.www.non-97.net
+masquerade_domains = $mydomain
+mydomain = www.non-97.net
+smtp_sasl_security_options = noanonymous
+smtp_tls_note_starttls_offer = yes
+smtp_sasl_tls_security_options = noanonymous
+smtp_sasl_auth_enable = yes
+smtp_sasl_mechanism_filter = digest-md5, plain
+relayhost = [email-smtp.us-east-1.amazonaws.com]:587
+smtpd_banner = $myhostname ESMTP unknown
+myorigin = $mydomain

$ sudo postfix check

Amazon SESのSMTPユーザーの認証情報を保存します。

$ sudo vi /etc/postfix/sasl_passwd
$ sudo cat /etc/postfix/sasl_passwd
[email-smtp.us-east-1.amazonaws.com]:587 <SMTPユーザー名 not IAMユーザー名>:<シークレットアクセスキー>

$ sudo postmap hash:/etc/postfix/sasl_passwd

$ ls -l /etc/postfix/sasl_passwd*
-rw-r--r--. 1 root root   107 Nov  3 12:21 /etc/postfix/sasl_passwd
-rw-r--r--. 1 root root 12288 Nov  3 12:21 /etc/postfix/sasl_passwd.db

$ ls -l /etc/postfix/sasl_passwd*
-rw-------. 1 root root   107 Nov  3 12:21 /etc/postfix/sasl_passwd
-rw-------. 1 root root 12288 Nov  3 12:21 /etc/postfix/sasl_passwd.db

Postfixを起動させます。

$ sudo systemctl enable postfix --now
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.

$ sudo systemctl status postfix● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Mon 2025-11-03 12:50:19 UTC; 7s ago
    Process: 3715 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid/master.pid (code=exited, status=255/EXCEPTION)
    Process: 3716 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 3718 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 3719 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
   Main PID: 3786 (master)
      Tasks: 3 (limit: 1053)
     Memory: 2.1M
        CPU: 373ms
     CGroup: /system.slice/postfix.service
             ├─3786 /usr/libexec/postfix/master -w
             ├─3787 pickup -l -t unix -u
             └─3788 qmgr -l -t unix -u

Nov 03 12:50:19 ip-172-31-23-99.ec2.internal systemd[1]: Starting postfix.service - Postfix Mail Transport Agent...
Nov 03 12:50:19 ip-172-31-23-99.ec2.internal restorecon[3715]: /usr/sbin/restorecon: lstat(/var/spool/postfix/pid/master.pid) failed: No such file or directory
Nov 03 12:50:19 ip-172-31-23-99.ec2.internal postfix/postfix-script[3784]: starting the Postfix mail system
Nov 03 12:50:19 ip-172-31-23-99.ec2.internal postfix/master[3786]: daemon started -- version 3.7.2, configuration /etc/postfix
Nov 03 12:50:19 ip-172-31-23-99.ec2.internal systemd[1]: Started postfix.service - Postfix Mail Transport Agent.

これで下準備は完了です。

正常なメール送信

実際にメールを送信してみましょう。

以下コマンドでPostfixのログを出力しておきます。

sudo journalctl -u postfix -f

別セッションでメールを送信します。

$ echo "mail body" | \
  mail \
    -r test@www.non-97.net \
    -s "mail subject" \
    <送信先メールアドレス>

journalctlの結果を確認すると以下ログが出力されていました。

Nov 03 12:57:23 ip-172-31-23-99.ec2.internal postfix/pickup[1517]: D1B9013D8FF: uid=1000 from=<test@www.non-97.net>
Nov 03 12:57:23 ip-172-31-23-99.ec2.internal postfix/cleanup[1872]: D1B9013D8FF: message-id=<6908a6b3.tRr+C7GjkfgTYrxp%test@www.non-97.net>
Nov 03 12:57:23 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: D1B9013D8FF: from=<test@www.non-97.net>, size=460, nrcpt=1 (queue active)
Nov 03 12:57:23 ip-172-31-23-99.ec2.internal postfix/smtp[1874]: warning: run-time library vs. compile-time header version mismatch: OpenSSL 3.2.0 may not be compatible with OpenSSL 3.0.0
Nov 03 12:57:23 ip-172-31-23-99.ec2.internal postfix/smtp[1874]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 12:57:24 ip-172-31-23-99.ec2.internal postfix/smtp[1874]: D1B9013D8FF: to=<<送信先メールアドレス>>, relay=email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587, delay=0.25, delays=0.01/0.02/0.11/0.1, dsn=2.0.0, status=sent (250 Ok 0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000)
Nov 03 12:57:24 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: D1B9013D8FF: removed

正常にリレーできたようです。

実際に受信できました。

5.送信されたメールの情報.png

原文は以下のとおりです。

Delivered-To: <送信先メールアドレス>
Received: by 2002:a05:6500:40ce:b0:2c0:fd44:55a6 with SMTP id bu14csp1351817lqb;
        Mon, 3 Nov 2025 04:57:24 -0800 (PST)
X-Google-Smtp-Source: AGHT+IG/f+F/SU9YiMBHc61RQ8I7yeWIW9MhGhcGPEO+lFAFKA0j28RY0+jZe78JYlZry58mF//P
X-Received: by 2002:ac8:5d04:0:b0:4b5:dc4f:7d67 with SMTP id d75a77b69052e-4ed218b2d97mr194735121cf.27.1762174644532;
        Mon, 03 Nov 2025 04:57:24 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1762174644; cv=none;
        d=google.com; s=arc-20240605;
        b=iCWuoiNdeo/abfys7yJ8kGPxGyhypCCYNRAmFEdO42l2PFFzhOwQJh9SvT+WJgxCKn
         nN9QQ/gD8WGA2KyjqIyopHxadd9BXhpKRepSEsLvU25DzR/sTSUZkrbuS5//ElJWM5tt
         hXYz+OR0QpFTFRpjU0+4x+h0+JraeKJiOc3NM0vq5TpXsUPzqaDuCNa6MA85MQZSBjLb
         Dt3qHF78pFh9co8BswSUzsO3uT0WpAq9HZG3393lWAIQomWVSn3gGLSWWYwvKUhklOo5
         1CfQKy9ePBmq5NpCFO5lPj63u1zyAE/TWPOSrDziM32G3pC87u1guU5vUhDgcuaIt+S0
         BXvw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605;
        h=feedback-id:content-transfer-encoding:mime-version:user-agent
         :message-id:subject:to:from:date:dkim-signature:dkim-signature;
        bh=fp1JTsWjk+OObhgkOjZFm+TxRremxmLO2Z4mRoSdFDo=;
        fh=RsXeDY2DPb6hRhIsFcWxCVYee0eiid4hQt4ZLoAWGM8=;
        b=eBgvYGnfTCm/ZUOLJvuesy/MHW0lrYt//iRTx68o21zQVX78OHJGkE1TspOd5VmxUp
         VFfAlzs/8WezmKCpBzzGjZgYE7H4QDH2EEYuYHN1Vd8/eRchr6xZ+r7uwk0IarsIt50P
         WpshSfvN70FDLQaNXwPbkbJrmFnAKWv7P27attetaIAleUp94QgmT7Vb+OsGIwG2Kxy8
         c3zT7+Ud6e/Jc8DAJUeMsgBCng18sSzb+UuE+9CMVyWI0r2WhwkKGN967nFCsbe4T+4q
         KdBR7yVV5hEPOGqui9HLX2SQ6oT2bK/L06W8KlYUMnTbFEjaetAPjecEnYCcdkWRCFU1
         /Sxw==;
        dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@www.non-97.net header.s=4dgyfjtt4esqedn6zhrqjb5qufw2yusr header.b="bpt1/8DF";
       dkim=pass header.i=@amazonses.com header.s=6gbrjpgwjskckoa6a5zn6fwqkn67xbtw header.b=r9oyOgLn;
       spf=pass (google.com: domain of 0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com designates 54.240.8.71 as permitted sender) smtp.mailfrom=0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com;
       dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=non-97.net
Return-Path: <0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com>
Received: from a8-71.smtp-out.amazonses.com (a8-71.smtp-out.amazonses.com. [54.240.8.71])
        by mx.google.com with ESMTPS id af79cd13be357-8ac0413c1b8si305793085a.1060.2025.11.03.04.57.24
        for <<送信先メールアドレス>>
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Mon, 03 Nov 2025 04:57:24 -0800 (PST)
Received-SPF: pass (google.com: domain of 0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com designates 54.240.8.71 as permitted sender) client-ip=54.240.8.71;
Authentication-Results: mx.google.com;
       dkim=pass header.i=@www.non-97.net header.s=4dgyfjtt4esqedn6zhrqjb5qufw2yusr header.b="bpt1/8DF";
       dkim=pass header.i=@amazonses.com header.s=6gbrjpgwjskckoa6a5zn6fwqkn67xbtw header.b=r9oyOgLn;
       spf=pass (google.com: domain of 0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com designates 54.240.8.71 as permitted sender) smtp.mailfrom=0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@amazonses.com;
       dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=non-97.net
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=4dgyfjtt4esqedn6zhrqjb5qufw2yusr; d=www.non-97.net; t=1762174644; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=fp1JTsWjk+OObhgkOjZFm+TxRremxmLO2Z4mRoSdFDo=; b=bpt1/8DFmsIKRm/S+Mdbc10ty6nafV7lP/5WZmUHWpk4u7iqpQ3ObbK/qyZNpilT JWp8OvDhYpIa7jlns5VlP1F9OQr/3olF1+YKbDGcBAyejOxH4dWpOVSbhAb5FnlsbhP 2vSCLy3jHlvy0lEucVkUc2V+mE6xQm1slQNP6ZETvWhM4xY4WozNIfpvTy52QYHP8/b YsXoXbQqgLnI0OjEuEl6+nimZpXp3ZQ/G5dT8qwPHbdz6OkR7vDMzWzFXZgokwZnUTW x2LQe/0BXTWBESBoPbAnSn3sJXIT/B/JCC9EZ/lw8lvXWMIo1s5yqQSEK64O3oT1sT+ Nf4srP/aGA==
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=6gbrjpgwjskckoa6a5zn6fwqkn67xbtw; d=amazonses.com; t=1762174644; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Feedback-ID; bh=fp1JTsWjk+OObhgkOjZFm+TxRremxmLO2Z4mRoSdFDo=; b=r9oyOgLnLFsdntxd4+pHyKqqpVVI4aRc1DbzR6rhtgjJ8Fiy85It7mN7aqCtmgTG Jaq5gsxIKixC9lye6ATmJzaNior5Xwm2mcC+Br+KlaI9bwcHi0r2B5egtBlIXVnmNc8 HpS0S6NuyYURa1fQGlpttZN+ffzVB1+7bd4ch8PY=
Date: Mon, 3 Nov 2025 12:57:24 +0000
From: test@www.non-97.net
To: <送信先メールアドレス>
Subject: mail subject
Message-ID: <0100019a49cb2f2e-7af4300a-356d-41dc-9fd3-6a64ebb0a3bf-000000@email.amazonses.com>
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Feedback-ID: ::1.us-east-1.blLBMNKJDXG50aImmo34J+R1uVs0K60dbZuyIR+ddeQ=:AmazonSES
X-SES-Outgoing: 2025.11.03-54.240.8.71

mail body

バウンスメールが発生する場合

続いて、バウンスメールが発生する場合を試します。

以下で紹介されているbounce@simulator.amazonses.com宛にメールを送信します。

https://docs.aws.amazon.com/ja_jp/ses/latest/dg/send-an-email-from-console.html

$ echo "mail body" | \
  mail \
    -r test@www.non-97.net \
    -s "mail subject" \
    bounce@simulator.amazonses.com

ログを確認すると、正常に配送されているようです。

Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/pickup[1517]: 084A213D8DD: uid=1000 from=<test@www.non-97.net>
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/cleanup[2523]: 084A213D8DD: message-id=<6908ab66.sKstWi24GnruRFNe%test@www.non-97.net>
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 084A213D8DD: from=<test@www.non-97.net>, size=461, nrcpt=1 (queue active)
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/smtp[2525]: warning: run-time library vs. compile-time header version mismatch: OpenSSL 3.2.0 may not be compatible with OpenSSL 3.0.0
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/smtp[2525]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/smtp[2525]: 084A213D8DD: to=<bounce@simulator.amazonses.com>, relay=email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587, delay=0.19,delays=0.02/0.02/0.04/0.11, dsn=2.0.0, status=sent (250 Ok 0100019a49dd86e3-e2cb72de-442c-4bb6-91fb-473e87b9158b-000000)
Nov 03 13:17:26 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 084A213D8DD: removed

SNS通知先に指定していたメール宛に以下の通知がきました。

{
  "notificationType": "Bounce",
  "bounce": {
    "feedbackId": "0100019a49dd887e-6dc89010-952a-4acc-8782-f9dc9b524bf9-000000",
    "bounceType": "Permanent",
    "bounceSubType": "General",
    "bouncedRecipients": [
      {
        "emailAddress": "bounce@simulator.amazonses.com",
        "action": "failed",
        "status": "5.1.1",
        "diagnosticCode": "smtp; 550 5.1.1 As requested: user unknown <bounce@simulator.amazonses.com>"
      }
    ],
    "timestamp": "2025-11-03T13:17:26.000Z",
    "remoteMtaIp": "107.23.2.81",
    "reportingMTA": "dns; a8-87.smtp-out.amazonses.com"
  },
  "mail": {
    "timestamp": "2025-11-03T13:17:26.115Z",
    "source": "test@www.non-97.net",
    "sourceArn": "arn:aws:ses:us-east-1:984900217833:identity/www.non-97.net",
    "sourceIp": "54.175.6.40",
    "callerIdentity": "ses-smtp-user.20251020-211719",
    "sendingAccountId": "984900217833",
    "messageId": "0100019a49dd86e3-e2cb72de-442c-4bb6-91fb-473e87b9158b-000000",
    "destination": [
      "bounce@simulator.amazonses.com"
    ],
    "headersTruncated": false,
    "headers": [
      {
        "name": "Received",
        "value": "from internal-mta.www.non-97.net (ec2-54-175-6-40.compute-1.amazonaws.com [54.175.6.40]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-XI3EAGGVF) id NyMvucP82zZ6SHXSyFnP for bounce@simulator.amazonses.com; Mon, 03 Nov 2025 13:17:26 +0000 (UTC)"
      },
      {
        "name": "Received",
        "value": "by internal-mta.www.non-97.net (Postfix, from userid 1000) id 084A213D8DD; Mon,  3 Nov 2025 13:17:26 +0000 (UTC)"
      },
      {
        "name": "Date",
        "value": "Mon, 03 Nov 2025 13:17:26 +0000"
      },
      {
        "name": "From",
        "value": "test@www.non-97.net"
      },
      {
        "name": "To",
        "value": "bounce@simulator.amazonses.com"
      },
      {
        "name": "Subject",
        "value": "mail subject"
      },
      {
        "name": "Message-ID",
        "value": "<6908ab66.sKstWi24GnruRFNe%test@www.non-97.net>"
      },
      {
        "name": "User-Agent",
        "value": "Heirloom mailx 12.5 7/5/10"
      },
      {
        "name": "MIME-Version",
        "value": "1.0"
      },
      {
        "name": "Content-Type",
        "value": "text/plain; charset=us-ascii"
      },
      {
        "name": "Content-Transfer-Encoding",
        "value": "7bit"
      }
    ],
    "commonHeaders": {
      "from": [
        "test@www.non-97.net"
      ],
      "date": "Mon, 03 Nov 2025 13:17:26 +0000",
      "to": [
        "bounce@simulator.amazonses.com"
      ],
      "messageId": "<6908ab66.sKstWi24GnruRFNe%test@www.non-97.net>",
      "subject": "mail subject"
    }
  }
}

バウンスが発生しているようですね。

SNS通知およびPostfixのログのどちらにもメッセージID6908ab66.sKstWi24GnruRFNe%test@www.non-97.netが記録されています。こちらを辿ればMTAのリレー元のIPアドレスが分かりますね。

メッセージIDはVirtual Deliverability Managerから確認することも可能です。(以下画像は実際に存在しないメールアドレス宛にメールを送信し、バウンスを発生させた時のもの)

9. Virtual Deliverability Manager ダッシュボード.png
10.メールの詳細.png

続いて実際に存在しないメールアドレス宛にメール送信をしてみます。

$ echo "mail body" | \
  mail \
    -r test@www.non-97.net \
    -s "mail subject" \
    test@non-97.net

ログ上では同様に配送に成功しています。

Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/pickup[1517]: 8B02A13D8DD: uid=1000 from=<test@www.non-97.net>
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/cleanup[2634]: 8B02A13D8DD: message-id=<6908ac1f.jmK2Z9ImAtQdH2tv%test@www.non-97.net>
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 8B02A13D8DD: from=<test@www.non-97.net>, size=446, nrcpt=1 (queue active)
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/smtp[2636]: warning: run-time library vs. compile-time header version mismatch: OpenSSL 3.2.0 may not be compatible with OpenSSL 3.0.0
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/smtp[2636]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/smtp[2636]: 8B02A13D8DD: to=<test@non-97.net>, relay=email-smtp.us-east-1.amazonaws.com[52.206.145.59]:587, delay=0.24, delays=0.02/0.02/0.04/0.16, dsn=2.0.0, status=sent (250 Ok 0100019a49e05ba8-7802f098-b7cd-48a3-b22f-b3d0499dae58-000000)
Nov 03 13:20:31 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 8B02A13D8DD: removed

SNS通知を確認すると、"notificationType":"Delivery"でした。

{
  "notificationType": "Delivery",
  "mail": {
    "timestamp": "2025-11-03T13:20:31.656Z",
    "source": "test@www.non-97.net",
    "sourceArn": "arn:aws:ses:us-east-1:984900217833:identity/www.non-97.net",
    "sourceIp": "54.175.6.40",
    "callerIdentity": "ses-smtp-user.20251020-211719",
    "sendingAccountId": "984900217833",
    "messageId": "0100019a49e05ba8-7802f098-b7cd-48a3-b22f-b3d0499dae58-000000",
    "destination": [
      "test@non-97.net"
    ],
    "headersTruncated": false,
    "headers": [
      {
        "name": "Received",
        "value": "from internal-mta.www.non-97.net (ec2-54-175-6-40.compute-1.amazonaws.com [54.175.6.40]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-0UH9YNGVF) id SXfomhUg8DZHPw5Nin2B for test@non-97.net; Mon, 03 Nov 2025 13:20:31 +0000 (UTC)"
      },
      {
        "name": "Received",
        "value": "by internal-mta.www.non-97.net (Postfix, from userid 1000) id 8B02A13D8DD; Mon,  3 Nov 2025 13:20:31 +0000 (UTC)"
      },
      {
        "name": "Date",
        "value": "Mon, 03 Nov 2025 13:20:31 +0000"
      },
      {
        "name": "From",
        "value": "test@www.non-97.net"
      },
      {
        "name": "To",
        "value": "test@non-97.net"
      },
      {
        "name": "Subject",
        "value": "mail subject"
      },
      {
        "name": "Message-ID",
        "value": "<6908ac1f.jmK2Z9ImAtQdH2tv%test@www.non-97.net>"
      },
      {
        "name": "User-Agent",
        "value": "Heirloom mailx 12.5 7/5/10"
      },
      {
        "name": "MIME-Version",
        "value": "1.0"
      },
      {
        "name": "Content-Type",
        "value": "text/plain; charset=us-ascii"
      },
      {
        "name": "Content-Transfer-Encoding",
        "value": "7bit"
      }
    ],
    "commonHeaders": {
      "from": [
        "test@www.non-97.net"
      ],
      "date": "Mon, 03 Nov 2025 13:20:31 +0000",
      "to": [
        "test@non-97.net"
      ],
      "messageId": "<6908ac1f.jmK2Z9ImAtQdH2tv%test@www.non-97.net>",
      "subject": "mail subject"
    }
  },
  "delivery": {
    "timestamp": "2025-11-03T13:20:32.224Z",
    "processingTimeMillis": 568,
    "recipients": [
      "test@non-97.net"
    ],
    "smtpResponse": "250 OK 05rbrhrefe4lf1tl6mtfnhejk10ue88a8uq2c601",
    "remoteMtaIp": "54.197.5.236",
    "reportingMTA": "a48-100.smtp-out.amazonses.com"
  }
}

もしや、と思いMXレコードを弾いていると対象ドメインのMXレコードを設定しており、Amazon SESでメールを受信するようにしていました。

> dig MX non-97.net +short
10 inbound-smtp.us-east-1.amazonaws.com.

つまりは、バウンスは発生しない状態になっていました。

IDが存在しない場合

送信元メールアドレスのドメインがAmazon SESのIDとして登録されていない場合の挙動を確認します。

www.non-97.netのIDを削除します。

6.削除 www.non-97.net.png

この状態でメールを送信します。

$ echo "mail body" | \
  mail \
    -r test@www.non-97.net \
    -s "mail subject" \
    <送信先メールアドレス>

この時のログは以下のとおりです。

Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/pickup[1517]: 6510113D8DD: uid=1000 from=<test@www.non-97.net>
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/cleanup[2755]: 6510113D8DD: message-id=<6908aceb.FexBPfPsASxTIAkc%test@www.non-97.net>
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 6510113D8DD: from=<test@www.non-97.net>, size=460, nrcpt=1 (queue active)
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/smtp[2757]: warning: run-time library vs. compile-time header version mismatch: OpenSSL 3.2.0 may not be compatible with OpenSSL 3.0.0
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/smtp[2757]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[3.224.1.122]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/smtp[2757]: 6510113D8DD: to=<<送信先メールアドレス>>, relay=email-smtp.us-east-1.amazonaws.com[3.224.1.122]:587, delay=0.26, delays=0.01/0.02/0.11/0.12, dsn=2.0.0, status=sent (250 Ok 0100019a49e37828-a553e1de-80af-4519-9481-f342cabdb12b-000000)
Nov 03 13:23:55 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 6510113D8DD: removed

正常にリレーできていますね。

これはAmazon SESのIDとしてnon-97.netが存在しているからです。

7.non-97.net.png

こちらの挙動は以下記事やAWS公式ドキュメントで紹介されています。

https://dev.classmethod.jp/articles/send-email-with-subdomain-of-verified-domain-in-ses-as-source-address/

ドメインの検証のみ E メールアドレスの検証のみ ドメインと E メールアドレスの両方の検証
継承レベル サブドメインと E メールアドレスは、親ドメインからの検証を継承します。 E メールアドレスは明示的に検証されます。 - サブドメインは親ドメインから検証を継承します。

- E メールアドレスは明示的に検証されます。
送信レベル E メールアドレスは単純な E メール送信に限定されます。 E メールアドレスは_高度な送信*_に使用できます。 E メールアドレスは_高度な送信*_に使用できます。
表示ステータス コンソール/API ステータス:

- ドメイン/サブドメイン = 検証済み

- E メールアドレス = 未検証。
コンソール/API ステータス:

- E メールアドレス = 検証済み
コンソール/API ステータス:

- ドメイン/サブドメイン = 検証済み

- E メールアドレス = 検証済み。

抜粋 : Amazon SES の ID の作成と検証 - Amazon Simple Email Service

non-97.netのIDを削除します。

8.削除 non-97.net.png

この状態でもう一度メールを送信します。

$ echo "mail body" | \
  mail \
    -r test@www.non-97.net \
    -s "mail subject" \
    <送信先メールアドレス>

この時のログは以下のとおりです。

Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/pickup[1517]: 6375913D8DD: uid=1000 from=<test@www.non-97.net>
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/cleanup[2980]: 6375913D8DD: message-id=<6908ae92.2ATsAhI+4P0Dzjt5%test@www.non-97.net>
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 6375913D8DD: from=<test@www.non-97.net>, size=460, nrcpt=1 (queue active)
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/smtp[2982]: warning: run-time library vs. compile-time header version mismatch: OpenSSL 3.2.0 may not be compatible with OpenSSL 3.0.0
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/smtp[2982]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[54.157.237.25]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/smtp[2982]: 6375913D8DD: to=<<送信先メールアドレス>>, relay=email-smtp.us-east-1.amazonaws.com[54.157.237.25]:587, delay=0.14, delays=0.01/0.02/0.04/0.07, dsn=5.0.0, status=bounced (host email-smtp.us-east-1.amazonaws.com[54.157.237.25] said: 554 Message rejected: Email address is not verified. The following identities failed the check in region US-EAST-1: test@www.non-97.net (in reply to end of DATA command))
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/cleanup[2980]: 8606813DBB1: message-id=<20251103133058.8606813DBB1@internal-mta.www.non-97.net>
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/bounce[2983]: 6375913D8DD: sender non-delivery notification: 8606813DBB1
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 8606813DBB1: from=<>, size=2862, nrcpt=1 (queue active)
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 6375913D8DD: removed
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/smtp[2982]: Verified TLS connection established to email-smtp.us-east-1.amazonaws.com[54.157.237.25]:587: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/smtp[2982]: 8606813DBB1: to=<test@www.non-97.net>, relay=email-smtp.us-east-1.amazonaws.com[54.157.237.25]:587, delay=0.04, delays=0/0/0.04/0, dsn=5.0.0, status=bounced (host email-smtp.us-east-1.amazonaws.com[54.157.237.25] said: 501 Invalid MAIL FROM address provided (in reply to MAIL FROM command))
Nov 03 13:30:58 ip-172-31-23-99.ec2.internal postfix/qmgr[1518]: 8606813DBB1: removed

リレーに失敗していることがPostfixのログから分かります。

バウンス通知やVirtual Deliverability Managerを有効活用しよう

Amazon SESのSMTPインターフェイスへセルフマネージドのMTAからSMTPリレーしている環境でバウンスの発生やAmazon SESに存在しないIDを用いた際に出力されるログを確認してみました。

バウンスしたメールはMTAのログから気づくことはできません。Amazon SESのバウンス通知を受け取るようにしたり、Virtual Deliverability Managerを使ってメールのリレー元を特定しましょう。

この記事が誰かの助けになれば幸いです。

以上、クラウド事業本部 コンサルティング部の のんピ(@non____97)でした!

この記事をシェアする

FacebookHatena blogX

関連記事