Amazon Simple Email Service Developer Guide Amazon Simple Email Service Developer Guide Amazon Simple Email Service: Developer Guide Copyright © 2018 Amazon Web Services, Inc. and/or its affiliates. All rights reserved. Amazon's trademarks and trade dress may not be used in connection with any product or service that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may or may not be affiliated with, connected to, or sponsored by Amazon. Amazon Simple Email Service Developer Guide Table of Contents What Is Amazon SES?......................................................................................................................... 1 Why use Amazon SES?................................................................................................................ 1 Amazon SES and other AWS services ............................................................................................ 1 In this guide.............................................................................................................................. 2 Quick Start........................................................................................................................................ 3 Step 1: Sign up for AWS ............................................................................................................. 3 Step 2: Verify your email address ................................................................................................. 3 Step 3: Send your first email ....................................................................................................... 3 Step 4: Consider how you will handle bounces and complaints ......................................................... 3 Step 5: Move out of the Amazon SES sandbox ............................................................................... 3 Next steps................................................................................................................................. 4 Sending Email................................................................................................................................... 5 How do I send emails using Amazon SES? ..................................................................................... 5 How do I start? .......................................................................................................................... 6 Concepts................................................................................................................................... 7 Amazon SES and Deliverability ............................................................................................ 7 Email-Sending Process...................................................................................................... 11 Email Format and Amazon SES .......................................................................................... 14 Getting Started........................................................................................................................ 16 Using the Amazon SES Console .......................................................................................... 17 Using Simple Mail Transfer Protocol (SMTP) ......................................................................... 17 Using an AWS SDK ........................................................................................................... 17 Before You Begin ............................................................................................................. 17 Send an Email Using the Console....................................................................................... 18 Send an Email Using SMTP................................................................................................ 19 Send an Email Using an AWS SDK ...................................................................................... 28 Setting up Email...................................................................................................................... 42 Signing up for AWS .......................................................................................................... 43 Verifying Identities........................................................................................................... 43 Getting Your AWS Access Keys ........................................................................................... 57 Downloading an AWS SDK ................................................................................................. 58 Using a Custom MAIL FROM Domain .................................................................................. 58 Setting up SPF Records ..................................................................................................... 64 Getting Your SMTP Credentials .......................................................................................... 64 Moving Out of the Sandbox .............................................................................................. 64 Sending Your Email.................................................................................................................. 66 Using the SMTP Interface .................................................................................................. 66 Using the API.................................................................................................................. 99 Sending Personalized Email ............................................................................................. 107 Authenticating Your Email ....................................................................................................... 115 Authenticating Email with SPF......................................................................................... 116 Authenticating Email with DKIM....................................................................................... 117 Complying with DMARC .................................................................................................. 126 Managing Your Sending Limits ................................................................................................. 127 Monitoring Your Sending Limits ....................................................................................... 128 Increasing Your Sending Limits ......................................................................................... 129 What Happens When You Reach Your Sending Limits .......................................................... 131 Using Sending Authorization.................................................................................................... 132 Overview of Sending Authorization ................................................................................... 132 Sending Authorization Policies ......................................................................................... 134 Sending Authorization Policy Examples ............................................................................. 138 Identity Owner Tasks ...................................................................................................... 144 Delegate Sender Tasks .................................................................................................... 149 Using Dedicated IP Addresses .................................................................................................. 156 iii Amazon Simple Email Service Developer Guide Ease of Setup................................................................................................................ 157 Reputation Managed by AWS ........................................................................................... 157 Predictability of Sending Patterns ..................................................................................... 157 Volume of Outbound Email ............................................................................................. 157 Additional Costs............................................................................................................. 158 Control over Sender Reputation ....................................................................................... 158 Ability to Isolate Sender Reputation .................................................................................. 158 Known, Unchanging IP Addresses ..................................................................................... 158 Requesting and Relinquishing Dedicated IPs ....................................................................... 158 Warming Up Dedicated IPs .............................................................................................. 160 Creating Dedicated IP Pools ............................................................................................. 162 Testing Email Sending ............................................................................................................. 162 Amazon SES and Security Protocols .......................................................................................... 164 Email Sender to Amazon SES ........................................................................................... 164 Amazon SES to Receiver .................................................................................................. 165 Receiving Email.............................................................................................................................. 166 Email-Receiving Concepts........................................................................................................ 166 Recipient-Based Control .................................................................................................. 166 IP Address-Based Control ................................................................................................ 167 Email-Receiving Process................................................................................................... 167 Getting Started Receiving Email ............................................................................................... 168 Step 1: Before You Begin ................................................................................................. 168 Step 2: Verify Your Domain ............................................................................................. 169 Step 3: Set up a Receipt Rule ........................................................................................... 172 Step 4: Send an Email..................................................................................................... 176 Step 5: View the Received Email ....................................................................................... 176 Step 6: Clean Up............................................................................................................ 179 Setting Up Email Receiving ...................................................................................................... 179 Considering Your Use Case .............................................................................................. 180 Verifying Your Domain .................................................................................................... 182 Publishing an MX Record ................................................................................................. 182 Giving Permissions.......................................................................................................... 182 Creating IP Address Filters ............................................................................................... 184 Creating a Receipt Rule Set ............................................................................................. 185 Creating Receipt Rules .................................................................................................... 185 Managing Email Receiving ....................................................................................................... 198 Managing Receipt Rule Sets ............................................................................................. 198 Managing Receipt Rules .................................................................................................. 201 Managing IP Address Filters ............................................................................................. 203 Viewing Error Metrics ...................................................................................................... 204 Using Notifications......................................................................................................... 204 Using Configuration Sets................................................................................................................. 215 Managing Configuration Sets................................................................................................... 215 Viewing a List of Your Configuration Sets .......................................................................... 215 Viewing the Details of a Configuration Set........................................................................ 216 Deleting a Configuration Set............................................................................................ 216 Managing Event Destinations ................................................................................................... 216 Updating an Event Destination ......................................................................................... 216 Deleting an Event Destination .......................................................................................... 217 Enabling or Disabling an Event Destination ........................................................................ 217 Managing IP Pools .................................................................................................................. 218 Assigning an IP Pool to a Configuration Set ....................................................................... 218 Modifying IP Pool Assignments ........................................................................................ 218 Specifying Configuration Sets in Email ...................................................................................... 219 Exporting Reputation Metrics ................................................................................................... 219 Enabling the Exporting of Reputation Metrics for a Configuration Set .................................... 219 Disabling the Exporting of Reputation Metrics for a Configuration Set ................................... 220 iv Amazon Simple Email Service Developer Guide Monitoring Your Sending Activity ..................................................................................................... 221 Monitoring Using the Console.................................................................................................. 222 Viewing Delivery and Rejection Metrics ............................................................................. 223 Monitor Using the API............................................................................................................. 223 Calling the GetSendStatistics API Operation Using the AWS CLI ..................................... 223 Calling the GetSendStatistics Operation Programmatically ............................................ 224 Monitoring Using Notifications................................................................................................. 226 Notifications Through Email ............................................................................................. 227 Notifications Through Amazon SNS .................................................................................. 229 Monitoring Using Event Publishing ........................................................................................... 247 How Event Publishing Works ............................................................................................ 247 How to Use Event Publishing ........................................................................................... 247 Event Publishing Terminology .......................................................................................... 248 Setting Up Event Publishing ............................................................................................ 248 Working with Event Data ................................................................................................. 256 Tutorials........................................................................................................................ 292 Configuring Custom Open and Click Domains.................................................................... 329 Monitoring Your Sender Reputation .................................................................................................. 332 Using the Reputation Dashboard .............................................................................................. 332 Reputation Dashboard Messages .............................................................................................. 333 General Status Messages................................................................................................. 334 Bounce Rate Notification ................................................................................................. 334 Complaint Rate Notification............................................................................................. 335 Anti-Spam Organization Notification ................................................................................. 336 Direct Feedback Notification ............................................................................................ 337 Domain Blocklist Notification........................................................................................... 338 Internal Review Notification ............................................................................................. 339 Mailbox Provider Notification ........................................................................................... 340 Recipient Feedback Notification ........................................................................................ 341 Related Account Notification ............................................................................................ 342 Spamtrap Notification..................................................................................................... 342 Vulnerable Site Notification ............................................................................................. 343 Other Notification.......................................................................................................... 344 Creating Alarms Using CloudWatch ........................................................................................... 344 Automatically Pausing Email Sending ........................................................................................ 346 Automatically Pausing Email Sending for Your Amazon SES Account ..................................... 346 Automatically Pausing Email Sending for a Configuration Set ............................................... 350 Controlling Access.......................................................................................................................... 357 Creating IAM Policies for Access to Amazon SES ......................................................................... 357 Restricting the Action ..................................................................................................... 357 Restricting Email Addresses ............................................................................................. 358 Restricting General API Usage .......................................................................................... 358 Example IAM Policies for Amazon SES ....................................................................................... 359 Allowing Full Access to All Amazon SES Actions ................................................................. 359 Allowing Access to Email-Sending Actions Only .................................................................. 359 Restricting the Time Period of Sending ............................................................................. 360 Restricting the Recipient Addresses ................................................................................... 360 Restricting the "From" Address ......................................................................................... 360 Restricting the Display Name of the Email Sender .............................................................. 361 Restricting the Destination of Bounce and Complaint Feedback ............................................ 361 Logging API Calls........................................................................................................................... 363 Amazon SES Information in CloudTrail ...................................................................................... 363 Understanding Amazon SES Log File Entries .............................................................................. 364 Using Credentials............................................................................................................................ 372 Using the API................................................................................................................................. 374 Query API.............................................................................................................................. 374 Query Requests.............................................................................................................. 374 v Amazon Simple Email Service Developer Guide Request Authentication................................................................................................... 376 GET and POST Examples ................................................................................................. 376 Query Responses............................................................................................................ 377 API Error Codes ...................................................................................................................... 379 Code Examples............................................................................................................................... 382 Sending Email using AWS SDKs ................................................................................................ 382 Sending Email using the SMTP Interface ................................................................................... 392 Sending Raw Email using AWS SDKs ......................................................................................... 403 Verify Multiple Email Addresses ................................................................................................ 410 Regions......................................................................................................................................... 412 Amazon SES Endpoints ........................................................................................................... 412 Email Sending Endpoints................................................................................................. 412 Email Receiving Endpoints ............................................................................................... 412 Selecting a Region .................................................................................................................. 413 Amazon SES API ............................................................................................................. 413 Amazon SES SMTP Interface ............................................................................................ 413 Amazon SES Console ...................................................................................................... 413 Sandbox and Sending Limit Increases ........................................................................................ 413 Verification............................................................................................................................ 414 Email Address Verification ............................................................................................... 414 Domain Verification........................................................................................................ 414 Easy DKIM Setup.................................................................................................................... 414 Suppression List..................................................................................................................... 414 Feedback Notifications............................................................................................................ 414 SMTP Credentials................................................................................................................... 415 Custom MAIL FROM Domains ................................................................................................... 415 Sending Authorization............................................................................................................. 415 Email Receiving...................................................................................................................... 415 Limits............................................................................................................................................ 416 Limits Related to Email Sending ............................................................................................... 416 Sending Limits............................................................................................................... 416 Message Limits............................................................................................................... 416 Sender and Recipient Limits ............................................................................................. 416 Limits Related to Email Sending Event Publishing ............................................................... 417 Amazon EC2-Related Limits ............................................................................................. 417 Limits Related to Email Receiving ............................................................................................. 417 General Limits........................................................................................................................ 418 Amazon SES API Limits ................................................................................................... 418 Best Practices................................................................................................................................. 419 Success Metrics...................................................................................................................... 419 Bounce Rate.................................................................................................................. 419 Complaints.................................................................................................................... 420 Message Quality............................................................................................................. 421 Tips and Best Practices ............................................................................................................ 421 General Recommendations.............................................................................................. 421 Domain and "From" Address Considerations ....................................................................... 422 Authentication............................................................................................................... 422 Building and Maintaining Your Lists .................................................................................. 422 Compliance.................................................................................................................... 423 Troubleshooting ............................................................................................................................. 424 General Issues........................................................................................................................ 424 Changes that I make are not immediately visible ................................................................ 424 Delivery Problems................................................................................................................... 425 Problems with Received Emails ................................................................................................ 425 Email Sending Errors ............................................................................................................... 426 Verification Problems.............................................................................................................. 427 Email Verification Problems ............................................................................................. 428 vi Amazon Simple Email Service Developer Guide Common Domain Verification Problems ............................................................................ 428 How to Check Domain Verification Settings ....................................................................... 429 DKIM Problems...................................................................................................................... 430 Notification Problems............................................................................................................. 431 Removing an Email Address from the Suppression List ................................................................ 431 Increasing Throughput............................................................................................................ 432 SMTP Issues........................................................................................................................... 433 SMTP Response Codes ............................................................................................................ 436 FAQs............................................................................................................................................. 439 Enforcement FAQs.................................................................................................................. 439 Probations..................................................................................................................... 439 Suspensions................................................................................................................... 441 Bounces......................................................................................................................... 443 Complaints.................................................................................................................... 445 Spamtraps..................................................................................................................... 449 Manual Investigations..................................................................................................... 451 IP Blacklist FAQs ..................................................................................................................... 452 Blacklist FAQ Q1 ............................................................................................................ 452 Blacklist FAQ Q2 ............................................................................................................ 453 Blacklist FAQ Q3 ............................................................................................................ 453 Blacklist FAQ Q4 ............................................................................................................ 453 Blacklist FAQ Q5 ............................................................................................................ 453 Email Metrics FAQs ................................................................................................................. 453 General......................................................................................................................... 454 Open Tracking................................................................................................................ 454 Click Tracking................................................................................................................. 455 Resources...................................................................................................................................... 457 Appendix....................................................................................................................................... 458 Appendix: Header Fields.......................................................................................................... 458 Appendix: Unsupported Attachment Types ................................................................................ 459 Appendix: Create a Deliverability Dashboard .............................................................................. 460 Part 1: Create an Amazon SNS Topic ................................................................................. 462 Part 2: Create an Amazon SQS Queue ............................................................................... 462 Part 3: Create an Amazon S3 Bucket ................................................................................. 463 Part 4: Create IAM Policy and Role ................................................................................... 463 Part 5: Configure Amazon SES Notifications ....................................................................... 465 Part 6: Create a Lambda Function .................................................................................... 465 Part 7: Test the Lambda Function ..................................................................................... 467 Part 8: Configure CloudWatch Triggers .............................................................................. 467 Document History.......................................................................................................................... 468 vii Amazon Simple Email Service Developer Guide Why use Amazon SES? What Is Amazon SES? Welcome to the Amazon Simple Email Service (Amazon SES) Developer Guide. Amazon SES is an email platform that provides an easy, cost-effective way for you to send and receive email using your own email addresses and domains. For example, you can send marketing emails such as special offers, transactional emails such as order confirmations, and other types of correspondence such as newsletters. When you use Amazon SES to receive mail, you can develop software solutions such as email autoresponders, email unsubscribe systems, and applications that generate customer support tickets from incoming emails. You only pay for what you use, so you can send and receive as much or as little email as you like. For service highlights, FAQs, and pricing information, go to the Amazon SES Detail Page. Why use Amazon SES? Building a large-scale email solution is often a complex and costly challenge for a business. You must deal with infrastructure challenges such as email server management, network configuration, and IP address reputation. Additionally, many third-party email solutions require contract and price negotiations, as well as significant up-front costs. Amazon SES eliminates these challenges and enables you to benefit from the years of experience and sophisticated email infrastructure Amazon.com has built to serve its own large-scale customer base. Amazon SES and other AWS services Amazon SES integrates seamlessly with other AWS products. For example, you can: • Add email capabilities to any application that runs on an Amazon Elastic Compute Cloud (Amazon EC2) instance by using the AWS SDKs or the Amazon SES API. If you want to send email through Amazon SES from an Amazon EC2 instance, you can get started with Amazon SES for free. • Use AWS Elastic Beanstalk to create an email-enabled application such as a program that uses Amazon SES to send a newsletter to customers. • Set up Amazon Simple Notification Service (Amazon SNS) to notify you of your emails that bounced, produced a complaint, or were successfully delivered to the recipient's mail server. When you use Amazon SES to receive emails, your email content can be published to Amazon SNS topics. • Use the AWS Management Console to set up Easy DKIM, which is a way to authenticate your emails. Although you can use Easy DKIM with any DNS provider, it is especially easy to set up when you manage your domain with Route 53. • Control user access to your email sending by using AWS Identity and Access Management (IAM). • Store emails you receive in Amazon Simple Storage Service (Amazon S3). • Take action on your received emails by triggering AWS Lambda functions. • Use AWS Key Management Service (AWS KMS) to optionally encrypt the mail you receive in your Amazon S3 bucket. • Use AWS CloudTrail to log Amazon SES API calls that you make using the console or the Amazon SES API. • Publish your email sending events to Amazon CloudWatch or Amazon Kinesis Firehose. If you publish your email sending events to Kinesis Firehose, you can access them in Amazon Redshift, Amazon Elasticsearch Service, or Amazon S3. 1 Amazon Simple Email Service Developer Guide In this guide In this guide This guide contains the following sections: Section Description Sending Email (p. 5) Describes how you can send email using Amazon SES. Receiving Email (p. 166) Describes how you can receive email using Amazon SES. Controlling Access (p. 357) Shows you how to use Amazon SES with AWS Identity and Access Management (IAM) to specify which Amazon SES API actions a user can perform on which Amazon SES resources. Logging API Calls (p. 363) Provides a list of Amazon SES APIs that can be logged using AWS CloudTrail. Using Credentials (p. 372) Explains the types of credentials that you might use with Amazon SES, and when you might use them. Using the API (p. 374) Describes how to use the Amazon SES Query API. Regions (p. 412) Lists the Amazon SES SMTP and API endpoints for the AWS regions in which Amazon SES is available, and contains information you need to know when you use Amazon SES endpoints in multiple regions. Limits (p. 416) Provides a list of limits within Amazon SES. Resources (p. 457) Lists resources that you may find useful as you work with Amazon SES Appendix (p. 458) Provides supplementary information about header fields, unsupported attachment types, and scripts. 2 Amazon Simple Email Service Developer Guide Step 1: Sign up for AWS Amazon SES Quick Start This procedure leads you through the steps to sign up for AWS, verify your email address, send your first email, consider how you will handle bounces and complaints, and move out of the Amazon Simple Email Service (Amazon SES) sandbox. Use this procedure if you: • Are just experimenting with Amazon SES. • Want to send some test emails without doing any programming. • Want to get set up in as few steps as possible. Step 1: Sign up for AWS Before you can use Amazon SES, you need to sign up for AWS. When you sign up for AWS, your account is automatically signed up for all AWS services. For instructions, see Signing up for AWS (p. 43). Step 2: Verify your email address Before you can send email from your email address through Amazon SES, you need to show Amazon SES that you own the email address by verifying it. For instructions, see Verifying Email Addresses in Amazon SES (p. 43). Step 3: Send your first email You can send an email simply by using the Amazon SES console. As a new user, your account is in a test environment called the sandbox, so you can only send email to and from email addresses that you have verified. For instructions, see Send an Email Using the Amazon SES Console (p. 18). Step 4: Consider how you will handle bounces and complaints Before the next step, you need to think about how you will handle bounces and complaints. If you are sending to a small number of recipients, your process can be as simple as examining the bounce and complaint feedback that you receive by email, and then removing those recipients from your mailing list. Step 5: Move out of the Amazon SES sandbox To be able to send emails to unverified email addresses and to raise the number of emails you can send per day and how fast you can send them, your account needs to be moved out of the sandbox. This process involves opening an SES Sending Limits Increase case in Support Center. 3
Description: