Amazon AWS SES/SNS: Bounce notifications don't include headers

596 Views Asked by At

I am using AWS SES for sending emails and SNS for notifications when an email is not delivered (bounced).

This is a bounce message I get when an email is not delivered:

{
  "notificationType"=>"Bounce", 
  "bounce"=>{
    "bounceType"=>"Permanent", 
    "bounceSubType"=>"General", 
    "bouncedRecipients"=>[{
      "emailAddress"=>"[email protected]", 
      "action"=>"failed", "status"=>"5.1.1", "diagnosticCode"=>"smtp; 550-5.1.1 The email account that you tried to reach does not exist. Please try\n550-5.1.1 double-checking the recipient's email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1  https://support.google.com/mail/?p=NoSuchUser b9si9302589pgt.293 - gsmtp"
      }], 
      "timestamp"=>"2019-02-17T08:31:24.795Z", 
      "feedbackId"=>"...", 
      "remoteMtaIp"=>"IP", 
      "reportingMTA"=>"dsn; SOMETHING.smtp-out.us-west-2.amazonses.com"}, 
      "mail"=>{"timestamp"=>"2019-02-17T08:31:24.000Z", 
        "source"=>"[email protected]", 
        "sourceArn"=>"AWS source", 
        "sourceIp"=>"IP", 
        "sendingAccountId"=>"ID #", 
        "messageId"=>"msg ID", 
        "destination"=>["[email protected]"]
      }
}

As I have an app where multiple users send many emails a day, I needed to identify what email failed - the object above doesn't provide this information. So I looked at the AWS SES documentation and found there the following response of the bounce object:

   {
       "notificationType":"Bounce",
       "bounce":{
          "bounceType":"Permanent",
          "reportingMTA":"dns; email.example.com",
          "bouncedRecipients":[
             {
                "emailAddress":"[email protected]",
                "status":"5.1.1",
                "action":"failed",
                "diagnosticCode":"smtp; 550 5.1.1 <[email protected]>... User"
             }
          ],
          "bounceSubType":"General",
          "timestamp":"2016-01-27T14:59:38.237Z",
          "feedbackId":"00000138111222aa-33322211-cccc-cccc-cccc-ddddaaaa068a-000000",
          "remoteMtaIp":"127.0.2.0"
       },
       "mail":{
          "timestamp":"2016-01-27T14:59:38.237Z",
          "source":"[email protected]",
          "sourceArn": "arn:aws:ses:us-west-2:888888888888:identity/example.com",
          "sourceIp": "127.0.3.0",
          "sendingAccountId":"123456789012",
          "messageId":"00000138111222aa-33322211-cccc-cccc-cccc-ddddaaaa0680-000000",
          "destination":[
            "[email protected]",
            "[email protected]",
            "[email protected]"],
          "headersTruncated":false,
          "headers":[ 
           { 
             "name":"From",
             "value":"\"John Doe\" <[email protected]>"
           },
           { 
             "name":"To",
             "value":"\"Jane Doe\" <[email protected]>, \"Mary Doe\" <[email protected]>, \"Richard Doe\" <[email protected]>"
           },
           { 
             "name":"Message-ID",
             "value":"custom-message-ID"
           },
           { 
             "name":"Subject",
             "value":"Hello"
           },
           { 
             "name":"Content-Type",
             "value":"text/plain; charset=\"UTF-8\""
           },
           { 
             "name":"Content-Transfer-Encoding",
             "value":"base64"
           },
           { 
             "name":"Date",
             "value":"Wed, 27 Jan 2016 14:05:45 +0000"
           }
          ],
          "commonHeaders":{ 
             "from":[ 
                "John Doe <[email protected]>"
             ],
             "date":"Wed, 27 Jan 2016 14:05:45 +0000",
             "to":[ 
                "Jane Doe <[email protected]>, Mary Doe <[email protected]>, Richard Doe <[email protected]>"
             ],
             "messageId":"custom-message-ID",
             "subject":"Hello"
           }
        }
    }

Great - here, under the mail key are also included the headers information that I need. So - here, in this article, I found out how to enable and include headers to the bounce notifications. I set it in my AWS dashboard as described in this article, but the headers information are still not included in the bounce object. I waited for 24 hours, as I thought there might be reserved some time for activation from the AWS side, but still nothing - the headers sub-object is still not included in the bounce object.

What am I overlooking yet? Are there needed some additional extra steps to include the headers information to the bounce notification?

0

There are 0 best solutions below