{SES}Amazon SESの設定セットの使用


https://dev.classmethod.jp/articles/amazon-ses-open-click-tracking/

https://docs.aws.amazon.com/ja_jp/ses/latest/dg/using-configuration-sets.html

 

-- 1. コマンド等のインストール

-- 1.1 aws cli version 2 インストール

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version

 

-- 1.2 jqインストール
sudo yum -y install jq

 

-- 2. Identityの作成

aws ses verify-email-identity \
--email-address hoge@example.com

aws ses list-identities

aws ses get-identity-verification-attributes \
--identities hoge@example.com


-- 3. 動作確認

aws ses send-email \
--from hoge@example.com \
--to hoge@example.com \
--subject "subject01" \
--text "text01"

 

 

-- 4. 設定セットの作成

vim cs01.json

{
    "ConfigurationSetName": "cs01",
    "DeliveryOptions": {
        "TlsPolicy": "OPTIONAL"
    },
    "ReputationOptions": {
        "ReputationMetricsEnabled": false
    },
    "SendingOptions": {
        "SendingEnabled": true
    },
    "Tags": []
}


aws sesv2 create-configuration-set \
--configuration-set cs01 \
--cli-input-json file://cs01.json

 

aws sesv2 list-configuration-sets

aws sesv2 get-configuration-set \
--configuration-set-name cs01


-- 5. イベント送信先の作成

aws sesv2 create-configuration-set-event-destination \
--configuration-set-name cs01 \
--event-destination-name dest01 \
--event-destination '{
            "Enabled": true,
            "MatchingEventTypes": [
                "OPEN",
                "CLICK",
                "SEND"
            ],
            "CloudWatchDestination": {
                "DimensionConfigurations": [
                    {
                        "DimensionName": "Dim",
                        "DimensionValueSource": "EMAIL_HEADER",
                        "DefaultDimensionValue": "dim11"
                    }
                ]
            }
        }'


aws sesv2 get-configuration-set-event-destinations \
--configuration-set-name cs01

 


-- 6. 動作確認


vim mail.txt

X-SES-MESSAGE-TAGS: Dim=mail11
X-SES-CONFIGURATION-SET: cs01
Subject: subject11
From: hoge@example.com
To: hoge@example.com
MIME-Version: 1.0
Content-Type:text/html

This is a test11.
<a href="https://htn20190109.hatenablog.com/">Click The Link !</a>

 

 


cat mail.txt | base64
cat mail.txt | base64 | tr -d "\n"
cat mail.txt | base64 | tr -d "\n" | base64 -d

 

vim mail.blob

{
  "Raw": {
    "Data": "9TFlrsgbraFNXXXtDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlrsgbraFNcZotDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlrsgbraFNcZotDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlrsgbraFNcZotDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlrsgbraFNcZotDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlrsgbraFNcZotDyg2zuXGrgS6A5mIRbDoGNiAGFubq4aQPGZse4Rinub9TFlr="
  }
}

 


aws sesv2 send-email \
--content file://mail.blob \
--configuration-set-name cs01 \
--from-email-address hoge@example.com

 

CloudWatchでメトリクスを確認


-- 7. クリーンアップ


-- イベント送信先の削除


aws sesv2 get-configuration-set-event-destinations \
--configuration-set-name cs01

aws sesv2 delete-configuration-set-event-destination \
--configuration-set-name cs01 \
--event-destination-name dest01

 

-- 設定セットの削除

aws ses list-configuration-sets

aws ses delete-configuration-set \
--configuration-set-name cs01

 


-- identityの削除

aws ses list-identities

aws ses delete-identity \
--identity hoge@example.com