Amazon Simple Email Service (SES) は AWS におけるメール送受信サービスです。基本的な使い方を記載します。
二つの SES API バージョンについて
SES API Action には v1 (classic) と v2 が存在しています。「ドキュメント」「aws cli」が v1 と v2 用にそれぞれ存在します。
補足: 「Web コンソール」にも二つのバージョンが存在しますが、これは API のバージョンとは関係のない UI の刷新です。
項目 | v1 (classic) | v2 |
---|---|---|
API Action | APIReference | APIReference-V2 |
Policy | resources and condition keys | resources and condition keys |
ドキュメント | DeveloperGuide | dg |
aws cli v1 | ses | sesv2 |
aws cli v2 | ses | sesv2 |
注意点: API Action は v1 であっても v2 であっても "ses:" に属します。また、v1 と v2 で扱うリソースは共通です。例えば、Email Identity を作成および削除するための API Action は、
- v1 の場合は
ses:VerifyEmailIdentity
とses:DeleteIdentity
であり - v2 の場合は
ses:CreateEmailIdentity
とses:DeleteEmailIdentity
ですが、
v1 で作成した Email Identity を v2 で削除することができます。その逆も可能です。
AWS CLI v1 と v2 について
最新バージョンの aws cli v1 と aws cli v2 を使っている限りにおいて、それらの差異は SES 利用という観点からは基本的にありません。ただし、aws cli v1 のバージョンが最新でない場合は、sesv2 に対応していない可能性があることに注意します。
確認方法の例
aws sesv2 help
参考: aws-cli レポジトリ
例えば sesv2 に関して以下のディレクトリが存在しています。
$ find . -name sesv2
./tests/functional/sesv2
最新のコミットを確認します。
$ git log ./tests/functional/sesv2
commit 3e88e154af61c8bd213cc27e87896454b7deb3f2
Author: Kenneth Daily <kdaily@users.noreply.github.com>
Date: Fri Oct 23 15:35:24 2020 -0700
add test.
コミットを含むタグは 1.18
以降です。それよりも古いバージョンの aws cli v1 は sesv2 に対応していない可能性があります。
$ git tag --contains=3e88e154af61c8bd213cc27e87896454b7deb3f2 | head
1.18.183
1.18.184
1.18.185
1.18.186
1.18.187
1.18.188
1.18.189
1.18.190
1.18.191
1.18.192
詳細は aws-cli が依存する botocore の実装を確認します。
$ git grep boto setup.py
setup.py: 'botocore==1.21.26',
SES API 全般について
- SES API は aws cli コマンドと基本的に一対一に対応しています。
- 例外となる場合の例: sesv2 の send-email コマンドで Simple メールを送信する場合は
ses:SendEmail
が必要となり、Raw メールを送信する場合はses:SendRawEmail
が必要となります。
- 例外となる場合の例: sesv2 の send-email コマンドで Simple メールを送信する場合は
- SES API によっては、マネジメントコンソールからも利用できます。情報のダウンロード機能等は存在しません。
- SES API によっては、Resource や Condition の指定が可能です。
Policy の Allow と Deny 判定について
ある API Action が Allow となるか Deny となるかは、ポリシーで判断されます。ポリシーは IAM Policy (Identity-based policy) の他に Resource-based policy や Organization SCP でも設定されます。
Determining whether a request is allowed or denied within an account
- Statement は Policy 内に複数記載できます。
- Allow に合致する Policy が存在しない場合は Implicit Deny となります。
- True となる Statement が Policy 内に一つでも存在していれば Poliy としては True になります。
- Condition が複数存在している場合は、すべてを満たす必要があります。
- Deny に合致する Policy が存在する場合は Allow に合致する Policy が存在していたとしても Explicit Deny となります。
PrivateLink VPC Endpoint について
SES は二種類のインターフェースを持ちます
- SMTP インターフェース
- HTTPS API インターフェース
関連資料
SES SMTP VPCE には Policy を設定できません
2021/8/30 時点において、
- PrivateLink VPC Endpoint (VPCE) に対応しているのは SMTP インターフェースのみです。
- SMTP インターフェースの VPCE には Policy を設定できません。
一般に、VPCE はネットワーク的に接続された別の VPC からも利用できます。別の VPC からであっても、VPCE と同じ VPC からであっても、Policy を設定できないため、他の AWS アカウントの IAM 認証情報を用いた VPCE 利用を制限することはできません。
関連資料
- Integrating AWS Transit Gateway with AWS PrivateLink and Amazon Route 53 Resolver
- Centralized access to VPC private endpoints
Policy の Resource および Condition について
Allow および Deny の「対象」および「条件」を指定
- Resource → Allow または Deny される「対象」を指定。
- Condition → Allow または Deny される「条件」を指定。
Resource を指定できる API Action と指定できない API Action
API Action によっては Resource を指定できません。その場合は Resource を省略せずに "*" を指定する必要があります。
注意点: 不正な Resource を指定すると Effect で指定した Allow および Deny が機能しなくなります。
{
"Id": "MyPolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "MyStatement",
"Effect": "Allow",
"Action": [
"ses:VerifyEmailIdentity"
],
"Resource": "*"
}
]
}
ある API Action において指定できる Resource はドキュメントに記載されています。
- Actions, resources, and condition keys for Amazon SES (補足ページ v1)
- Actions, resources, and condition keys for Amazon Simple Email Service v2 (補足ページ v2)
Condition について
Condition には Key と Value を記載します。記載できる Key には、
- SES サービスによって定められたもの
- SES サービスに依らないもの: AWS global condition context keys
が存在しています。
その他の関連ドキュメント
- Creating a condition with multiple keys or values
- ARN の指定方法について
- Condition の value には変数を指定することもできます: Information available in all requests
Email Identity 作成および削除 API
AWS CLI
aws ses verify-email-identity --email-address abc@gmail.com
aws sesv2 create-email-identity --email-identity abc@gmail.com
aws ses list-identities
aws sesv2 list-email-identities
aws ses delete-identity --identity abc@gmail.com
aws sesv2 delete-email-identity --email-identity abc@gmail.com
Policy
DeleteEmailIdentity
については Resource 指定が可能です。
注意: DeleteIdentity
はドキュメント上は可能と記載がありますが、実際には機能しません。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:VerifyEmailIdentity",
"ses:CreateEmailIdentity",
"ses:ListIdentities",
"ses:ListEmailIdentities",
"ses:DeleteIdentity"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ses:DeleteEmailIdentity"
],
"Resource": "arn:aws:ses:ap-northeast-1:123412341234:identity/*"
}
]
}
Condition 指定の例
Policy の Condition を設定する例を記載します。以下の例では v2 の API Action のみを記載しています。TagResource
の権限も必要です。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ses:ListEmailIdentities"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ses:TagResource",
"ses:CreateEmailIdentity"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"aws:TagKeys": ["mytag1", "mytag2"]
},
"StringEquals": {
"aws:RequestTag/mytag1": ["a", "b"],
"aws:RequestTag/mytag2": ["c", "d"]
}
}
},
{
"Effect": "Allow",
"Action": [
"ses:DeleteEmailIdentity"
],
"Resource": "arn:aws:ses:ap-northeast-1:123412341234:identity/*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/mytag1": ["a", "b"],
"aws:ResourceTag/mytag2": ["c", "d"]
}
}
}
]
}
動作検証のためのコマンド
aws sesv2 create-email-identity --email-identity abc@gmail.com --tags 'Key=mytag1,Value=a' 'Key=mytag2,Value=c'
aws sesv2 delete-email-identity --email-identity abc@gmail.com
Evaluation logic for conditions with multiple keys or values
- 上図で AND となっている箇所がすべて True となった場合に Policy として True になります。
--tags
で 0 個以上のタグが指定され得ります。CreateEmailIdentity
ForAllValues:StringEquals
aws:TagKeys
→--tags
で指定されたタグの key が condition の value として取得できます。すべての tag-key (condition-value) がmytag1
またはmytag2
であることを求めています。ForAllValues
の仕様として、指定されたタグの個数が 0 である場合も True となります。
StringEquals
aws:RequestTag/mytag1
→mytag1
タグの value が condition の value として取得できます。tag-value (condition-value) がa
またはb
であることを求めています。指定されたタグの個数が 0 の場合は False となります。aws:RequestTag/mytag2
→mytag2
タグの value が condition の value として取得できます。tag-value (condition-value) がc
またはd
であることを求めています。指定されたタグの個数が 0 の場合は False となります。
DeleteEmailIdentity
StringEquals
aws:ResourceTag/mytag1
→ Resource が持つ mytag1 タグの value が condition の value として取得できます。tag-value (condition-value) がa
またはb
であることを求めています。aws:ResourceTag/mytag2
→ Resource が持つ mytag2 タグの value が condition の value として取得できます。tag-value (condition-value) がc
またはd
であることを求めています。
aws:TagKeys
が複数の value を返すのに対して、aws:RequestTag/xxx
および aws:ResourceTag/xxx
が一つの value しか返さないことがポイントです。
メール送信 API
- 送信先メールアドレスは、アカウントのリージョンが Sandbox である場合は verify されている必要があります。
- 送信元メールアドレスは、アカウントのリージョンの Sandbox 設定に依らず verify されている必要があります。
AWS CLI
aws sesv2 send-email \
--from-email-address abc@gmail.com \
--destination ToAddresses=abc@gmail.com \
--content '{
"Simple": {
"Subject": {
"Data": "MySubject",
"Charset": "UTF-8"
},
"Body": {
"Text": {
"Data": "MyBody",
"Charset": "UTF-8"
}
}
}
}'
aws ses send-email \
--from abc@gmail.com \
--destination ToAddresses=abc@gmail.com \
--subject MySubject2 \
--text MyBody2
--feedback-forwarding-email-address
を指定していない、上記例におけるFeedbackAddress
はabc@gmail.com
となります。--destination
をa <abc@gmail.com
とした場合は、FromDisplayName
は "" ではなく "a" となります。- v2 の API Action 一覧に記載がありませんが、"Simple" ではなく "Raw" および "Template" メールを送信するためには
ses:SendRawEmail
とses:SendTemplatedEmail
権限が必要になります。
Policy
{
"Effect": "Allow",
"Action": [
"ses:SendEmail",
"ses:SendRawEmail",
"ses:SendTemplatedEmail"
],
"Resource": "arn:aws:ses:ap-northeast-1:123412341234:identity/*",
"Condition": {
"StringEquals": {
"ses:FeedbackAddress": "abc@gmail.com",
"ses:FromAddress": "abc@gmail.com",
"ses:FromDisplayName": ""
},
"ForAllValues:StringEquals": {
"ses:Recipients": "abc@gmail.com"
}
}
}
Recipients
は複数の value を返すためForAllValues
またはForAnyValue
を併用します。- Condition で指定できるオペレータ
StringEquals
等について: Condition operators
アカウント情報の設定 API
AWS CLI
get-account
SES には Sandbox という概念があり、これが有効になっていると verify された宛先にしかメールを送信できず、送信できるメールの数にも強い制限がかかります。v2 の API を用いて設定を確認できます。
aws sesv2 get-account
出力例
{
"DedicatedIpAutoWarmupEnabled": true,
"EnforcementStatus": "HEALTHY",
"SendQuota": {
"Max24HourSend": 200.0,
"SentLast24Hours": 15.0,
"MaxSendRate": 1.0
},
"SuppressionAttributes": {
"SuppressedReasons": [
"BOUNCE",
"COMPLAINT"
]
},
"ProductionAccessEnabled": false, ← sandbox 状態
"SendingEnabled": true
}
アカウント情報の更新
aws sesv2 put-account-details --mail-type TRANSACTIONAL \
--website-url https://www.qoosky.io \
--use-case-description 'Emails for testing purposes of SES functionalities.' \
--contact-language JA \
--production-access-enabled
オプション --production-access-enabled
を指定すると、AWS サポートが対応するためのケースが起票されます。上記のように十分な情報が記載されていないと却下されます。
アカウントのメール送信を一時的に強制停止
aws sesv2 put-account-sending-attributes --sending-enabled
account-level suppression list の有効化および無効化
一般に、メールサーバが送信したメールが BOUNCE および COMPLAINT されるとメールサーバの IP の信頼性が落ちます。これを避けるために SES では suppression list が用意されています。suppression list には global のものと account-level のものが存在します。account-level の suppression list について、BOUNCE および COMPLAINT されたメールアドレスを自動で含めるかどうかの設定が可能です。2019/11/25 以降、既定の挙動が変更されており、BOUNCE および COMPLAINT が含まれるように初期設定されています。
aws sesv2 put-account-suppression-attributes --suppressed-reasons 'COMPLAINT' 'BOUNCE'
関連資料:
Policy
{
"Effect": "Allow",
"Action": [
"ses:GetAccount",
"ses:PutAccountDetails",
"ses:PutAccountSendingAttributes",
"ses:PutAccountSuppressionAttributes"
],
"Resource": "*"
}
put-account-details に関する awscli のバグについて
Value at 'websiteURL' failed to satisfy constraint...
上記のようなエラーが出力されることがあります。こちらの Pull Request で修正されています: https://github.com/aws/aws-cli/pull/5663
最新のバージョンの awscli にアップグレードすることで修正を取り込みます。
$ python -m pip list | grep awscli
awscli 1.18.147
$ sudo yum install python-pip
$ python -m pip install --upgrade pip
$ python -m pip install --upgrade awscli
$ python -m pip list | grep awscli
awscli 1.19.112
account-level suppression list の操作 API
AWS CLI
aws sesv2 list-suppressed-destinations
aws sesv2 get-suppressed-destination --email-address abc@gmail.com
aws sesv2 put-suppressed-destination --email-address abc@gmail.com --reason COMPLAINT
aws sesv2 delete-suppressed-destination --email-address abc@gmail.com
Policy
{
"Effect": "Allow",
"Action": [
"ses:ListSuppressedDestinations",
"ses:GetSuppressedDestination",
"ses:PutSuppressedDestination",
"ses:DeleteSuppressedDestination"
],
"Resource": "*"
}
Email テンプレートの操作 API
AWS CLI
aws ses list-templates
aws sesv2 list-email-templates
aws ses create-template --template TemplateName=mytemplate,SubjectPart=MySubject,TextPart=MyText
aws sesv2 create-email-template --template-name mytemplate2 --template-content Subject=MySubject2,Text=MyText2
aws ses get-template --template-name mytemplate
aws sesv2 get-email-template --template-name mytemplate
aws ses update-template --template TemplateName=mytemplate,SubjectPart=MySubject3,TextPart=MyText3
aws sesv2 update-email-template --template-name mytemplate2 --template-content Subject=MySubject4,Text=MyText4
aws ses delete-template --template mytemplate
aws sesv2 delete-email-template --template mytemplate2
aws ses test-render-template --template-name mytemplate3 --template-data '{"name":"a","favoriteanimal":"b"}'
aws sesv2 test-render-email-template --template-name mytemplate3 --template-data '{"name":"a","favoriteanimal":"b"}'
Policy
v1 と v2 で操作するテンプレートリソースは共通ですが、コマンドおよび API は別々に存在します。v2 の API の一部は Resource 指定が可能です。
{
"Effect": "Allow",
"Action": [
"ses:ListTemplates",
"ses:GetTemplate",
"ses:CreateTemplate",
"ses:UpdateTemplate",
"ses:DeleteTemplate",
"ses:TestRenderTemplate",
"ses:ListEmailTemplates",
"ses:CreateEmailTemplate"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ses:GetEmailTemplate",
"ses:UpdateEmailTemplate",
"ses:DeleteEmailTemplate",
"ses:TestRenderEmailTemplate"
],
"Resource": "arn:aws:ses:ap-northeast-1:123412341234:template/*"
}
Email テンプレートを用いた送信 API
AWS CLI
aws ses send-templated-email \
--source abc@gmail.com \
--destination ToAddresses=abc@gmail.com \
--template mytemplate \
--template-data '{}'
aws sesv2 send-email \
--from-email-address abc@gmail.com \
--destination ToAddresses=abc@gmail.com \
--content '{
"Template": {
"TemplateName": "mytemplate",
"TemplateData": "{}"
}
}'
aws ses send-bulk-templated-email \
--source abc@gmail.com \
--template mytemplate \
--default-template-data '{}' \
--destinations Destination={ToAddresses=abc@gmail.com}
aws sesv2 send-bulk-email \
--from-email-address abc@gmail.com \
--default-content '{
"Template": {
"TemplateName": "mytemplate",
"TemplateData": "{}"
}
}' \
--bulk-email-entries Destination={ToAddresses=abc@gmail.com}
Policy
SendTemplatedEmail
は v1 と v2 で共通です。v1 の SendBulkTemplatedEmail
には Resource と Condition を設定できますが、v2 の SendBulkEmail
には設定できません。
{
"Effect": "Allow",
"Action": [
"ses:SendTemplatedEmail",
"ses:SendBulkTemplatedEmail"
],
"Resource": "arn:aws:ses:ap-northeast-1:123412341234:identity/*",
"Condition": {
"StringEquals": {
"ses:FeedbackAddress": "abc@gmail.com",
"ses:FromAddress": "abc@gmail.com",
"ses:FromDisplayName": ""
},
"ForAllValues:StringEquals": {
"ses:Recipients": "abc@gmail.com"
}
}
},
{
"Effect": "Allow",
"Action": [
"ses:SendBulkEmail"
],
"Resource": "*"
}
関連資料: テンプレートメールに動的に値を埋め込む設定 Using templates to send personalized emails with the Amazon SES API
Identity 利用を他のアカウントに許可するための API
SES における resource-based policy
Email Identity または Domain Identity の利用を、他のアカウントの同じリージョンに許可することができます。これは SES における resource-based policy であり、S3 バケットポリシーと同様に policy は resouce が持ちます。
注意: 別のアカウントに対して resource-based policy を与えた場合、与えられたアカウント側でも policy を利用するための IAM 設定が必要となります。
関連資料
- How IAM roles differ from resource-based policies
- Identity-based policies and resource-based policies
- Overview of Amazon SES Sending Authorization
- Policy anatomy
- Cross-account policy evaluation logic
AWS CLI
v1:list-identity-policies
v1:get-identity-policies
v1:put-identity-policy
v1:delete-identity-policy
v2:get-email-identity-policies
v2:create-email-identity-policy
v2:update-email-identity-policy
v2:delete-email-identity-policy
Policy
v1:ListIdentityPolicies
v1:GetIdentityPolicies
v1:PutIdentityPolicy
v1:DeleteIdentityPolicy
v2:GetEmailIdentityPolicies
v2:CreateEmailIdentityPolicy
v2:UpdateEmailIdentityPolicy
v2:DeleteEmailIdentityPolicy
Domain Identity 作成に関する API
API を実行した後に、ドメインの DNS レコード設定が必要になります。
補足: v2 の create-email-identity
は Email Identity だけでなく Domain Identity 作成にも対応しています。
AWS CLI
v1:verify-domain-identity
v1:get-identity-verification-attributes
v1:get-identity-mail-from-domain-attributes
v1:set-identity-mail-from-domain
v2:put-email-identity-mail-from-attributes
v1:verify-domain-dkim
v1:get-identity-dkim-attributes
v1:set-identity-dkim-enabled
v2:put-email-identity-dkim-attributes
v2:put-email-identity-dkim-signing-attributes
Policy
v1:VerifyDomainIdentity
v1:GetIdentityVerificationAttributes (注意: ドキュメントに記載の resource 指定は機能しません)
v1:GetIdentityMailFromDomainAttributes (注意: ドキュメントに記載の resource 指定は機能しません)
v1:SetIdentityMailFromDomain (注意: ドキュメントに記載の resource 指定は機能しません)
v2:PutEmailIdentityMailFromAttributes
v1:VerifyDomainDkim (注意: ドキュメントに記載の resource 指定は機能しません)
v1:GetIdentityDkimAttributes (注意: ドキュメントに記載の resource 指定は機能しません)
v1:SetIdentityDkimEnabled (注意: ドキュメントに記載の resource 指定は機能しません)
v2:PutEmailIdentityDkimAttributes
v2:PutEmailIdentityDkimSigningAttributes
Email Identity 作成時の verification email をカスタマイズするための API
Email Identity を作成する際の確認メールをカスタマイズするための API です。verify-email-identity
および create-email-identity
ではなく send-custom-verification-email
を利用して Email Identity を登録します。その際、利用するテンプレートを指定します。
関連資料: Using custom verification email templates
AWS CLI
v1,v2共通:send-custom-verification-email
v1,v2共通:list-custom-verification-email-templates
v1,v2共通:get-custom-verification-email-template
v1,v2共通:create-custom-verification-email-template
v1,v2共通:update-custom-verification-email-template
v1,v2共通:delete-custom-verification-email-template
Policy
v1,v2共通:SendCustomVerificationEmail
v1,v2共通:ListCustomVerificationEmailTemplates
v1,v2共通:GetCustomVerificationEmailTemplate
v1,v2共通:CreateCustomVerificationEmailTemplate
v1,v2共通:UpdateCustomVerificationEmailTemplate
v1,v2共通:DeleteCustomVerificationEmailTemplate
メール受信時の挙動を設定するための API
一部の AWS リージョンは SES を用いたメール受信に対応しています。2021/9/1 時点: us-east-1, us-west-2, eu-west-1
一般のメールサーバのように POP や IMAP には対応しておらず、メール受信時に Lambda 実行や S3 保存が可能です。
Amazon SES email receiving concepts and use cases
関連資料: Receiving email with Amazon SES
AWS CLI
v1:describe-receipt-rule
v1:create-receipt-rule
v1:update-receipt-rule
v1:delete-receipt-rule
v1:list-receipt-filters
v1:create-receipt-filter
v1:delete-receipt-filter
v1:list-receipt-rule-sets
v1:describe-receipt-rule-set
v1:describe-active-receipt-rule-set
v1:set-active-receipt-rule-set
v1:create-receipt-rule-set
v1:clone-receipt-rule-set
v1:delete-receipt-rule-set
v1:reorder-receipt-rule-set
v1:set-receipt-rule-position
v1:send-bounce
Policy
v1:DescribeReceiptRule
v1:CreateReceiptRule
v1:UpdateReceiptRule
v1:DeleteReceiptRule
v1:ListReceiptFilters
v1:CreateReceiptFilter
v1:DeleteReceiptFilter
v1:ListReceiptRuleSets
v1:DescribeReceiptRuleSet
v1:DescribeActiveReceiptRuleSet
v1:SetActiveReceiptRuleSet
v1:CreateReceiptRuleSet
v1:CloneReceiptRuleSet
v1:DeleteReceiptRuleSet
v1:ReorderReceiptRuleSet
v1:SetReceiptRulePosition
v1:SendBounce
configuration-set 関連の API
SES には configuration-set というリソースが存在します。configuration-set はメール送信時の設定群です。大別すると以下の二つの設定を記載可能です。
- 各種 event が発生した際に行なう処理。
- Dedicated IPs を用いた送信。
メール送信時に都度指定することで configuration-set を利用します。Identity に対して default の configuration-set を指定しておくこともできます。
Managing configuration sets in Amazon SES: v1, v2
configuration-set 作成および削除
AWS CLI
aws ses list-configuration-sets
aws ses create-configuration-set --configuration-set Name=myconf
aws ses delete-configuration-set --configuration-set-name myconf
aws ses describe-configuration-set --configuration-set-name myconf \
--configuration-set-attribute-names eventDestinations trackingOptions deliveryOptions reputationOptions
aws sesv2 list-configuration-sets
aws sesv2 create-configuration-set --configuration-set-name myconf
aws sesv2 delete-configuration-set --configuration-set-name myconf
aws sesv2 get-configuration-set --configuration-set-name myconf
Policy
v1,v2共通:ListConfigurationSets
v1,v2共通:CreateConfigurationSet
v1,v2共通:DeleteConfigurationSet
v1:DescribeConfigurationSet
v2:GetConfigurationSet
event-destination 作成および削除
AWS CLI
aws ses create-configuration-set-event-destination \
--configuration-set-name myconf \
--event-destination Name=mydest,Enabled=true,MatchingEventTypes=[send,bounce,complaint,delivery],SNSDestination={TopicARN=arn:aws:sns:ap-northeast-1:123412341234:mytopic}
aws sesv2 create-configuration-set-event-destination \
--configuration-set-name myconf \
--event-destination-name mydest \
--event-destination Enabled=false,MatchingEventTypes=[SEND,BOUNCE,COMPLAINT,DELIVERY],SnsDestination={TopicArn=arn:aws:sns:ap-northeast-1:123412341234:mytopic}
aws sesv2 get-configuration-set-event-destinations --configuration-set-name myconf
aws ses update-configuration-set-event-destination --configuration-set-name myconf \
--event-destination Name=mydest,Enabled=true,MatchingEventTypes=[send,bounce,complaint,delivery],SNSDestination={TopicARN=arn:aws:sns:ap-northeast-1:123412341234:mytopic}
aws sesv2 update-configuration-set-event-destination --configuration-set-name myconf \
--event-destination-name mydest \
--event-destination Enabled=true,MatchingEventTypes=[SEND,BOUNCE,COMPLAINT,DELIVERY],SnsDestination={TopicArn=arn:aws:sns:ap-northeast-1:123412341234:mytopic}
aws ses delete-configuration-set-event-destination --configuration-set-name myconf --event-destination-name mydest
aws sesv2 delete-configuration-set-event-destination --configuration-set-name myconf --event-destination-name mydest
Policy
v1,v2共通:CreateConfigurationSetEventDestination
v2:GetConfigurationSetEventDestinations
v1,v2共通:UpdateConfigurationSetEventDestination
v1,v2共通:DeleteConfigurationSetEventDestination
configuration-set の利用例
メール送信時に都度指定
aws ses send-email \
--from abc@gmail.com \
--destination ToAddresses=abc@gmail.com \
--subject MySubject \
--text MyBody \
--configuration-set-name myconf
Email Identity または Domain Identity に default 値を指定
注意: put-email-identity-configuration-set-attributes
は比較的新しいバージョンの awscli に実装されています。また "email-identity" ですが domain identity にも対応しています。
aws sesv2 put-email-identity-configuration-set-attributes --email-identity abc@gmail.com \
--configuration-set-name myconf
v2:PutEmailIdentityConfigurationSetAttributes
SNS Topic に通知されるメッセージ例: Examples of event data that Amazon SES publishes to Amazon SNS
その他の configuration
AWS CLI
v1:update-configuration-set-sending-enabled
v2:put-configuration-set-sending-options
v1:create-configuration-set-tracking-options
v1:delete-configuration-set-tracking-options
v1:update-configuration-set-tracking-options
v2:put-configuration-set-tracking-options
v1:put-configuration-set-delivery-options
v2:put-configuration-set-delivery-options
v1:update-configuration-set-reputation-metrics-enabled
v2:put-configuration-set-reputation-options
v2:put-configuration-set-suppression-options
Policy
v1:UpdateConfigurationSetSendingEnabled
v2:PutConfigurationSetSendingOptions
v1:CreateConfigurationSetTrackingOptions
v1:DeleteConfigurationSetTrackingOptions
v1:UpdateConfigurationSetTrackingOptions
v2:PutConfigurationSetTrackingOptions
v1,v2共通:PutConfigurationSetDeliveryOptions
v1:UpdateConfigurationSetReputationMetricsEnabled
v2:PutConfigurationSetReputationOptions
v2:PutAccountSuppressionAttributes
notification 関連の API
SES における Bounce, Complaint, Delivery イベントの処理方法としては、以下の二種類が存在します。
- configuration-set による event 処理。
- identity notification による event 処理。
- 直接 Identity に対して行います。
- Bounce, Complaint, Delivery イベントのみ。
- 処理方法は feedback mail または SNS トピックのみ。
- Bounce, Complaint → feedback mail および SNS の両方が対応。
- Delivery → SNS のみ対応。
関連資料:
- Monitoring Amazon SES email sending using notifications
- Setting up event notification for Amazon SES
AWS CLI
aws ses get-identity-notification-attributes --identities abc@gmail.com
aws ses set-identity-feedback-forwarding-enabled --identity abc@gmail.com --forwarding-enabled
aws sesv2 put-email-identity-feedback-attributes --email-identity abc@gmail.com --email-forwarding-enabled
aws ses set-identity-notification-topic --identity abc@gmail.com \
--notification-type Delivery \
--sns-topic arn:aws:sns:ap-northeast-1:123412341234:mytopic
aws ses set-identity-headers-in-notifications-enabled --identity abc@gmail.com --notification-type Delivery --enabled
補足: Notification に Subject 等のヘッダー情報を含めるためには set-identity-headers-in-notifications-enabled
を利用します。
Policy
v1:GetIdentityNotificationAttributes (注意: ドキュメントに記載の resource 指定は機能しません)
v1:SetIdentityFeedbackForwardingEnabled (注意: ドキュメントに記載の resource 指定は機能しません)
v2:PutEmailIdentityFeedbackAttributes
v1:SetIdentityNotificationTopic
v1:SetIdentityHeadersInNotificationsEnabled (注意: ドキュメントに記載の resource 指定は機能しません)
Bounce 時に Feedback メールを受信する例
Forwarding を有効化
aws ses set-identity-feedback-forwarding-enabled --identity qoosky.io --forwarding-enabled
qoosky.io
ドメインで bounce メールを受信できない場合は return-path に verify 済みの Identity を指定します。
補足: bounce@simulator.amazonses.com
を利用すると、アカウントの reputation に影響を与えずに設定を検証できます: Testing email sending in Amazon SES
aws ses send-email --from hello@qoosky.io \
--destination ToAddresses=bounce@simulator.amazonses.com \
--subject MySubject --text MyBody \
--return-path abc@gmail.com
Feedback メールは「メール受信」機能とは別です。東京リージョンでも利用できます。
関連記事
- AWS EC2 インスタンスの選定方法準仮想化と完全仮想化 AWS のインスタンスタイプが準仮想化と完全仮想化のどちらの仮想化技術を採用したハードウェアであるかによって、使用できる AMI (OS) が異なるのは以下の理由によります。 準仮想化 ParaVirtualization (PV) において OS は自分が仮想化用のハードウェア上で動作していることを知っています。つまり仮想化用にカスタマイズされた専用の OS が必要になりま...
- OpenVPN で二つの VPC をつなぐための設定インターネット VPN (Virtual Private Network) には二拠点間の通信を暗号化する方式によって IPsec-VPN や SSL-VPN などがあります。OpenVPN は SSL-VPN の実装のひとつです。AWS VPC を二つ用意してそれらを OpenVPN で接続してみます。 VPC の構成 myvpc-1 (10.1.0.0/16) mysubnet-1-1 (10...
- Windows Server EC2 インスタンスへの CAL インストールWindows サーバを AWS EC2 インスタンスとして起動した後は、RDP 接続が必要となります。RDP 接続を行なうためには Remote Desktop Services (RDS) ライセンスが必要となります。 Windows Server のライセンスは、管理用途の RDS 接続を許可しています。その際に RDS ライセンスは不要です。ただし、[同時接続数が 2 という制限があります...
- AWS Lambda の基本的な使い方AWS Lambda はイベントドリブンな「関数」を登録できるサービスです。例えば S3 に画像がアップロードされたときにサムネイル用のサイズに加工する処理が記述された関数を登録できます。基本的な使い方をまとめます。 事前準備 関数の登録はブラウザで AWS コンソールにログインして行うこともできますが、本ページでは AWS C
- AWS 落穂拾い (Data Engineering)Kinesis Kinesis Streams データは 3 AZ にレプリケーションされます。Amazon Kinesis Data Streams FAQs 24 時間 (既定値) から 1 年までデータ保持できます。[Changing the Data Retention Period](https://docs.aws.amazon