3

I have a setup with CiviCRM and Amazon SES, everything is working fine.

A Problem arises with the bounce handling. Amazon can either do that internally via Amazon SNS, or just forward the mails to your domain for common handling (Catchall or VERP).

I wanted to use the SNS mechanism, and amazon sends the mail correctly to the specified address, but the email isn't a typical bounce mail, but instead the original headers are JSON encoded like this:

{   "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-11-20T11:05:06.477Z",
    "feedbackId": "0102015fd91a6479-ae22395c-1f7d-4423-a9e5-e0715bffc731-000000",
    "remoteMtaIp": "1.2.3.4",
    "reportingMTA": "dsn; a4-8.smtp-out.eu-west-1.amazonses.com"   },   "mail": {
    "timestamp": "2017-11-20T11:05:04.000Z",
    "source": "bounce.crm+b.83.52.2a7c92a4101dd5fd@example.com",
    "sourceArn": "ARN_INTERNAL:identity/example.com",
    "sourceIp": "1.2.3.4",
    "sendingAccountId": "__ID__",
    "messageId": "0102015fd91a5ca3-93c245fe-e333-46ae-8fed-96160d20cfab-000000",
    "destination": ["bounce@simulator.amazonses.com"],
    "headersTruncated": false,
    "headers": [{
      "name": "Received",
      "value": "from crm.example.com (mx02.example.com [1.2.3.4]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-2638500019) id MbY8b9mKuaex7LdPcwd8 for bounce@simulator.amazonses.com; Mon, 20 Nov 2017 11:05:04 +0000 (UTC)"
    }, {
      "name": "MIME-Version",
      "value": "1.0"
    }, {
      "name": "Content-Type",
      "value": "multipart/alternative; boundary=\"=_99c8dccfc484a99b0f6101141a34c4ae\""
    }, {
      "name": "Reply-To",
      "value": "\"Example Company\" <info@example.com>"
    }, {
      "name": "Return-Path",
      "value": "bounce.crm+b.83.52.2a7c92a4101dd5fd@example.com"
    }, {
      "name": "From",
      "value": "\"Example Company\" <info@example.com>"
    }, {
      "name": "Subject",
      "value": "Bounce Test – Monday 4"
    }, {
      "name": "List-Unsubscribe",
      "value": "<mailto:bounce.crm+u.83.52.2a7c92a4101dd5fd@example.com>"
    }, {
      "name": "job_id",
      "value": "83"
    }, {
      "name": "To",
      "value": "Tom TestUser <bounce@simulator.amazonses.com>"
    }, {
      "name": "Precedence",
      "value": "bulk"
    }, {
      "name": "X-CiviMail-Bounce",
      "value": "bounce.crm+b.83.52.2a7c92a4101dd5fd@example.com"
    }, {
      "name": "Date",
      "value": "Mon, 20 Nov 2017 12:05:04 +0100"
    }],
    "commonHeaders": {
      "returnPath": "bounce.crm+b.83.52.2a7c92a4101dd5fd@example.com",
      "from": ["Example Company <info@example.com>"],
      "replyTo": ["Example Company <info@example.com>"],
      "date": "Mon, 20 Nov 2017 12:05:04 +0100",
      "to": ["Tom TestUser <bounce@simulator.amazonses.com>"],
      "subject": "Bounce Test – Monday 4"
    }   } }

Civi cannot handle this type of message (to the best of my knowledge) and it is then moved to the ignored folder. I'm pretty sure I am not the first one to have this problem, but I couldn't find any solutions to this. Maybe someone has written a parser for those type of messages already?

Help/Suggestions are welcome!

  • If you want Civi to handle the bounce directly, why not just use the email option in SES rather than SNS? – Aidan Nov 20 '17 at 14:26
  • doesn't work! I don't have a catchall/VERP handling, and I don't receive the original emails, only the JSON formatted ones. Might be that I have something misconfigured, but I'm pretty sure I tried all options! – Phil_B Nov 20 '17 at 15:17
  • Did you have any joy with this in the end, Phil_B? – michaelmcandrew Apr 19 '18 at 7:25
  • 1
    cool - will do :) – michaelmcandrew Apr 19 '18 at 9:06
  • 1
    @michaelmcandrew I'm working on an extension to support bounce handling via SES/SNS, I'll keep you posted by the end of this week – Andrei May 7 '18 at 11:27
3

I've created an extension to handle bounces through Amazon SNS notifications, see civicrm-ses.

It exposes a webhook to process SNS notifications and map and create bounces when appropriate.

Hope you find it useful.

PS: although the extension is in alpha stage, I've been using it in production for a month (~60,000 emails processed), test in a dev environment first if you like :)

  • Was on holiday, will check soon and give feedback! Thanks for the post! – Phil_B Jun 20 '18 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.