How to Track Bounced Email after User Sending a Mail using Laravel

Using Laravel handles the email bounce notifications from AWS

Introduction

In the previous story (How to Handling Bounced And Complaint Notification in AWS within 15 minutes), it explained how to configure notifications in AWS.

You’ll learn how to implement the code with notifications from this topic.

Scenario

A current user wants to invite a new User B through email, and be your connection circle.

It’s a simple mockup. Senders need to know the status of the email invitation has been sent successfully. Therefore, we’ll show the email status to the sender after the Webhook has been triggered by AWS.

Definition

Webhook: is an HTTP callback, an HTTP POST that occurs when it gets a notification.

Query Responses and Amazon SES: In response to a query request, Amazon SES returns an XML data structure that contains the results of the request.

Flow

Receiving a message ID from AWS, storing it to the database (notification table). We can use the message ID to identify which one is a bounce email.

Let’s Coding

Dispatch an email

Create a SendNotificationEmail job instance.

The Message ID must be stored in your database. You’ll need the message ID to identify any problematic email messages that you have sent.

This route handles the notification from AWS SNS.
If a message is rejected or bounced, the message ID will appear in any complaint or bounce notifications that you receive.

Install SNS Message Validator

Amazon SNS Message Validator for PHP allows you to validate that incoming HTTP(S) POST messages are valid Amazon SNS notifications.
$ composer require aws/aws-php-sns-message-validator

I hope this will help you gain a better understanding of bounced mail :)

REFERENCE

Like what you read? Give Eder a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.