# Mautic & Amazon SES-SNS bounce handling

**URL:** <https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192>\
**Category:** Product Support\
**Created:** [December 30, 2021, 3:02pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192 "2021-12-30T15:02:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/nickbm/32/6488_2.png) [@nickbm](https://forum.mautic.org/u/nickbm)\
**Post date:** [December 30, 2021, 3:02pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/1 "2021-12-30T15:02:36Z")

</div>

Hi,

I have configured SES and Mautic as described here:  
[Bounce management | Mautic](https://docs.mautic.org/en/channels/emails/bounce-management)

However, I’m not sure that bounce handling is actually working.  
The segment that contains all bounced emails (Filtering Bounced - Emails equal Yes) has 0 contacts.

The SNS topic is confirmed.

Is there a webhook log or a log can help me identify what’s going on in the background with the Amazon SNS?

Or any other log for that matter?

Thanks  
Nick

My Mautic version is: 4.1.0  
My PHP version is: 7.4.27  
My Database type and version is: MySQL 8.0.27

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 2, 2022, 11:36am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/2 "2022-01-02T11:36:50Z")

</div>

Same problem here and same configuration.  
Let me add some information.

when I edit SNS in the log file I can see this entries:

[2022-01-02 11:23:15] mautic.NOTICE: PHP Notice - Undefined index: Type - in file /mnt/BLOCKSTORAGE/home/xxx.cloudwaysapps.com/ewsjjdghuj/public\_html/app/bundles/EmailBundle/Swiftmailer/Amazon/AmazonCallback.php - at line 156 {“payload”:{“notificationType”:“AmazonSnsSubscriptionSucceeded”,“message”:“You have successfully subscribed your Amazon SNS topic ‘arn:aws:sns:us-east-1:4x9587392918:xxxBounceComplaints’ to receive ‘Bounce’ notifications from Amazon SES for identity ‘newsletter@xxxxx.com’.”},“type”:“AmazonSnsSubscriptionSucceeded”}   
[2022-01-02 11:23:15] mautic.WARNING: Received SES webhook of type ‘’ but couldn’t understand payload

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/a/ae207e3a675366e869739bd4ab686d2e979096b6.png)

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/e/e216ef39f4ce5ada6fa0553be095b90e4014c1e5.png)

Also Cloudwatch confirm that SNS is working successfully

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/3/36217ac93ca4c1d0a7e418466a4b80807f714706.png)

No idea how to deal … right now added forward to email and fetching using old email this is working

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 2, 2022, 7:22pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/3 "2022-01-02T19:22:59Z")

</div>

Additional test:

- Moved to a different region (eu-central-1) nothing changed
- In my configuration Cloudflare is between
- Setting up debug mode NO ERROR and NO COMMUNICATION from SNS

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 3, 2022, 7:58am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/4 "2022-01-03T07:58:35Z")

</div>

You need to be in the same region for SNS and SES. I assume it was the same in the beginning.

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 3, 2022, 10:53am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/5 "2022-01-03T10:53:44Z")

</div>

Yes Joeyk, they are synced so in domain1 they are in N. Virginia (for both SES and SNS)and domain2 is in eu.central (for both SES and SNS)

The notification are verified so, I presume, communication is established. also cloudwatch show that notification are successfully delivered. Seems that mautic is fully ignoring that information.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 3, 2022, 4:33pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/6 "2022-01-03T16:33:03Z")

</div>

> [@massimo0307](#):
>
> Received SES webhook of type ‘’ but couldn’t understand payload

I’m worried about this:  
Received SES webhook of type ‘’ but couldn’t understand payload

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 3, 2022, 6:21pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/7 "2022-01-03T18:21:16Z")

</div>

Me too. Any additional test or place to look for information? the most frustrating thing is not finding any error or information …

Do the bounce configuration have any impact in  
Configuration-\>Email\>Bounce settings if we are using API , should no in my understanding.

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 5, 2022, 4:36pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/8 "2022-01-05T16:36:03Z")

</div>

The only workaround is to work using IMAP in bounce management.  
not efficient and very slow … hopefully, we’ll find a solution since we would like to stay with Mautic after all the time we have invested in preparing the environment.

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 9, 2022, 12:47am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/9 "2022-01-09T00:47:19Z")

</div>

Any idea? Next step is give up with aws

---

<div class="post-metadata">

**Author:** ![rory.madden](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/rory.madden/32/6648_2.png) [@rory.madden](https://forum.mautic.org/u/rory.madden)\
**Post date:** [January 11, 2022, 7:46am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/10 "2022-01-11T07:46:56Z")

</div>

I’m having the same issue. I checked the logs for SNS and the message is being sent correctly, with a 200 response from mautic:  
{  
“notification”: {  
“messageId”: “88f3827b-58f9-4315-9aca-123456789”,  
“topicArn”: “arn:aws:sns:eu-west-1:1234567899:bounces”,  
“timestamp”: “2022-01-11 05:19:21.594”  
},  
“delivery”: {  
“deliveryId”: “xyz”,  
“destination”: “[https://MYDOMAIN.com/mailer/amazon\_api/callback](https://MYDOMAIN.com/mailer/amazon_api/callback)”,  
“providerResponse”: “OK”,  
“dwellTimeMs”: 317,  
“attempts”: 1,  
“statusCode”: 200  
},  
“status”: “SUCCESS”  
}

But there is nothing in my logs in Mautic (System Information \> Logs) and the contacts aren’t being flagged.

I don’t have any Monitored Inbox Settings set as I am using the Amazon\_API setup.

Any idea where to look to see if things aren’t set up correctly?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 11, 2022, 10:11am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/11 "2022-01-11T10:11:21Z")

</div>

I can confirm, that something is off with the bounce management. I’m trying to get more logs.  
I does work with emails sent from M3 versions, but M4 seems not to work. It is not the capturing events, but my theory is, that we are sending wrong, and this is why the data is not coming back right.

I’m doing some tests now, soon back with results.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 11, 2022, 12:44pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/12 "2022-01-11T12:44:31Z")

</div>

Hi,  
I set up a log for all incoming json notifications from amazon sns.

There are 2 major type of bounces.

**Part 1: Permanent**

In case of permanent failure this arrives from SNS:

```auto
{
  "Type" : "Notification",
  "Message" : "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bouncedRecipients\":[{\"emailAddress\":\"info@email.com\",\"diagnosticCode\":\"smtp; 550 no such address here\"}]},\"mail\":{\"destination\":[\"info@email.com\"]}}"
  }

```

If you want to test if it works, you can do it by POST curl to `https://yourdomain/mailer/amazon_api/callback`

with the JSON body above.  
Choose an email address existing in your system and NOT in the `lead_donotcontact` table.  
Once you post this content to the right URL, a new entry will be added to the table and the person will have a DNC, similar to this:

![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/f/fca942341b59e102cc07711da8ac1fc0f3e22678.png)

> Important to know: the json feedback is not coming right away from Amazon SNS, as they also need to get some answer from the postbox of the recipient. This makes it really hard to test.

**Part 2:**

In case of temporary, or so calles Transient failure you would see something like this:

```auto
{
  "Type" : "Notification",
  "Message" : "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Transient\",\"bouncedRecipients\":[{\"emailAddress\":\"info@email.com\",\"diagnosticCode\":\"smtp; 552 5.2.2 Quota exceeded (mailbox for user is full)\"}]},\"mail\":{\"destination\":[\"info@email.com\"]}}"
  }

```

But after posting this, I can’t see any trace of this notification in Mautic. It would be logical, that the bounce info is saved in the DNC table as softbounce, but I couldn’t find any info related. Also no new entries in lead\_event\_log.

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 11, 2022, 4:24pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/13 "2022-01-11T16:24:21Z")

</div>

Great work Joeyk,  
probably the community need to open an issue on this?!  
how we can support?

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [January 11, 2022, 6:28pm UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/14 "2022-01-11T18:28:11Z")

</div>

Thanks @joeyk for tagging me in this issue. Let me clarify how the callback function works, I think it would explain the issue:

1. There is no distinction between soft and hard bounces in the callback, any SNS notification Mautic gets will mark the contact as DNC. Personally, I do not think soft bounces should not be marked as DNC after the first attempt. but because of the complexity of implementation, I made it mark contacts as DNC when a soft bounce happens.

2. In case you are using ConfigSets in SES, there is no need to configure callbacks from the domain as described in the documentation. just configure the ConfigSet to use SNS. Using ConfigSet and Domain Callbacks will make the JSON object returned to Mautic to who wrong dataset and Mautic will halt.

3. Becasue you are great, you will go to this _PR and review it ([fix SES API limits by mabumusa1 · Pull Request #9735 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/9735))_

@massimo0307 Please follow these steps just to be sure:

1. Disable Include Original Headers, in the domain (in your case email address)
2. Make sure that you are sending from the verified email, if you are sending from the same domain that the verified email is on, you need to add SNS to that domain as well

---

<div class="post-metadata">

**Author:** ![rory.madden](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/rory.madden/32/6648_2.png) [@rory.madden](https://forum.mautic.org/u/rory.madden)\
**Post date:** [January 12, 2022, 6:55am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/15 "2022-01-12T06:55:10Z")

</div>

> [@joeyk](#):
>
> I set up a log for all incoming json notifications from amazon sns

Thanks - how do I go about setting up a log like this? It works like you said when I curl post but I have emails that should be triggering a permanent failure and they are not getting updated. I’d like to see what amazon is sending.

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 12, 2022, 7:32am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/16 "2022-01-12T07:32:46Z")

</div>

I wrote a script that captures the incoming payload and writes the log.  
You need to code the SNS topic verification part as well in order to be able to register with SNS.  
My code is really messy and many things hard coded, let me clean it up and post it here or on my page.

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 12, 2022, 8:38am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/17 "2022-01-12T08:38:29Z")

</div>

Already done in previous testing with 0 success.  
0 bounce while complains seems working.

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [January 12, 2022, 10:05am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/18 "2022-01-12T10:05:21Z")

</div>

I just tested the code on the latest version, it works as expected.

to test create a contact with email `nope@nope.com`, and then send a request with the below payload which I took from the test case

```auto
    "Type": "Notification",
    "MessageId": "7c2d7069-7db3-53c8-87d0-20476a630fb6",
    "TopicArn": "arn:aws:sns:eu-west-1:918057160339:55hubs-mautic-test",
    "Message": "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"nope@nope.com\",\"action\":\"failed\",\"status\":\"5.1.1\",\"diagnosticCode\":\"smtp; 550 5.1.1 <nope@nope.com>: Recipient address rejected: User unknown in virtual alias table\"}],\"timestamp\":\"2016-08-17T07:43:12.776Z\",\"feedbackId\":\"0102015697743d4c-619f1aa8-763f-4bea-8648-0b3bbdedd1ea-000000\",\"reportingMTA\":\"dsn; a4-24.smtp-out.eu-west-1.amazonses.com\"},\"mail\":{\"timestamp\":\"2016-08-17T07:43:11.000Z\",\"source\":\"admin@55hubs.ch\",\"sourceArn\":\"arn:aws:ses:eu-west-1:918057160339:identity/nope.com\",\"sendingAccountId\":\"918057160339\",\"messageId\":\"010201569774384f-81311784-10dd-48a8-921f-8316c145e64d-000000\",\"destination\":[\"nope@nope.com\"]}}",
    "Timestamp": "2016-08-17T07:43:12.822Z",
    "SignatureVersion": "1",
    "Signature": "GNWnMWfKx1PPDjUstq2Ln13+AJWEK/Qo8YllYC7dGSlPhC5nClop5+vCj0CG2XN7aN41GhsJJ1e+F4IiRxm9v2wwua6BC3mtykrXEi8VeGy2HuetbF9bEeBEPbtbeIyIXJhdPDhbs4anPJwcEiN/toCoANoPWJ3jyVTOaUAxJb2oPTrvmjMxMpVE59sSo7Mz2+pQaUJl3ma0UgAC/lrYghi6n4cwlDTfbbIW+mbV7/d/5YN/tjL9/sD3DOuf+1PpFFTPsOVseZWV8PQ0/MWB2BOrKOKQyF7msLNX5iTkmsvRrbYULPvpbx32LsIxfNVFZJmsnTe2/6EGaAXf3TVPZA==",
    "SigningCertURL": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem",
    "UnsubscribeURL": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:918057160339:nope:1cddd2a6-bfa8-4eb5-b2b2-a7833eb5db9b"
}

![image|690x387](upload://6nDKc1UwRWNeRoUzoVDOWL7tyTF.png)
```

---

<div class="post-metadata">

**Author:** ![massimo0307](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/massimo0307/32/6285_2.png) [@massimo0307](https://forum.mautic.org/u/massimo0307)\
**Post date:** [January 12, 2022, 10:24am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/19 "2022-01-12T10:24:06Z")

</div>

> [@m.abumusa](#):
>
> k from the test

Ehy can you share how you get this information? I’ll test with [bounce@amazonas.com](mailto:bounce@amazonas.com) the email offered by amazon for this kind of tests

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [January 12, 2022, 11:06am UTC](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192/20 "2022-01-12T11:06:08Z")

</div>

> [@m.abumusa](#):
>
> ```auto
> ![image|690x387](upload://6nDKc1UwRWNeRoUzoVDOWL7tyTF.png)
> 
> ```

This is the first time I see the address, we test using the simulator of SES

[https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-simulator.html](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-email-simulator.html)

For JSON Payload samples, you can find them here

> <https://github.com/mautic/mautic/blob/dc152081cdbf212ea502bb954452600885334192/app/bundles/EmailBundle/Tests/Transport/AmazonApiTransportTest.php>

[Next page](https://forum.mautic.org/t/mautic-amazon-ses-sns-bounce-handling/22192.md?page=2)
