How to Handling Bounced And Complaint Notification in AWS within 15 minutes

Eder
Quick Code
Published in
3 min readAug 14, 2018

Introduction

Email marketing is important for building relationships with customers. I had been working on an invitation project that bounces emails could be tracked by users and our marketing.

Let’s get started to build a production-ready Email Bounce Tracking system based on the AWS.

In this article you will learn the following:

  • Setting up Simple Email Service (SES) with Simple Notification Service (SNS) on AWS
  • AWS Email sending process
  • … Or more than you expect?

An overview of the sending process

The following figure describes what happens when you send an email with Amazon SES.

If the sender’s request to SES succeeds, then it sends the email and one of the following results happen:

  • bounce
  • complaint
  • successful

SNS provides a way to handle bounces and complaint notifications

To receive notification published to a topic, you have to subscribe an endpoint to that topic. An endpoint is a mobile app, web server, email, or an Amazon SQS queue that can receive notification messages from Amazon SNS.

Once you subscribe an endpoint to a topic and the subscription is confirmed, the endpoint will receive all messages published to that topic. Learn AWS with the Best AWS Course & Certification for beginners.

Configuration Bounce Notifications

  1. Create an Amazon SNS topic named ses-bounces-topic.

Then you get an identity id is called ARN, you’ll need it later.

2. Configure the Amazon SNS topic to publish to the endpoint.

2.1: Create a subscription with that ARN you just created

Surely, not done yet… you have to confirm that endpoint from AWS SNS.

AWS SNS will send you a Subscription confirmation URL to your endpoint, then you have to verify it.

3. Configure Amazon SES to publish bounce notifications using ses-bounces-topic.

Using the Mailbox Simulator for testing

To use the email simulator: bounce@simulator.amazonses.com

You’ll get the following message after sending a bounce email

{
"notificationType":"Bounce",
"bounce":{
"bounceType":"Permanent",
"bounceSubType":"General",
"bouncedRecipients":[
{
"emailAddress":"bounce@simulator.amazonses.com",
"action":"failed",
"status":"5.1.1",
"diagnosticCode":"smtp; 550 5.1.1 user unknown"
}
],
"timestamp":"2017-09-05T02:30:25.645Z",
"feedbackId":"0101015e4fdfe031-818e3e45-3db7-4546-8bbf-6da232afc8e9-000000",
"remoteMtaIp":"207.171.163.188",
"reportingMTA":"dsn; a27-24.smtp-out.us-west-2.amazonses.com"
},
"mail":{
"timestamp":"2017-09-05T02:30:24.000Z",
"source":"bounce111@eder.com.au",
"sourceArn":"arn:aws:ses:us-west-2:154131996403:identity/eder.com",
"sourceIp":"54.240.230.242",
"sendingAccountId":"154131996403",
"messageId":"0101015e4fdfdb7f-a3dcaf07-8fb3-459f-9343-7859c0398c3f-000000",
"destination":[
"bounce@simulator.amazonses.com"
],
"headersTruncated":false,
"headers":[
{
"name":"From",
"value":"bounce111@eder.com.au"
},
{
"name":"To",
"value":"bounce@simulator.amazonses.com"
},
{
"name":"Subject",
"value":"bounce@simulator.amazonses.com"
},
{
"name":"MIME-Version",
"value":"1.0"
},
{
"name":"Content-Type",
"value":"text/plain; charset=UTF-8"
},
{
"name":"Content-Transfer-Encoding",
"value":"7bit"
}
],
"commonHeaders":{
"from":[
"bounce111@eder.com.au"
],
"to":[
"bounce@simulator.amazonses.com"
],
"subject":"bounce@simulator.amazonses.com"
}
}
}

Epilogue

That’s all! Easy, right?

I had been researching for a while to understand how to implement them.

I would like to share with you what I learn from the real-world project. I hope it can save you time.

Thank you for reading:)

To be continued on the next story: How to Track Bounced Email after User Sending a Mail using Laravel

--

--