cividesk / com.cividesk.email.sparkpost

This extension allows CiviCRM to send emails and process bounces through the SparkPost service.
10 stars 30 forks source link

Callback post data is a bounce but getting undefined property: X-CiviMail-Bounce #81

Closed herbdool closed 5 years ago

herbdool commented 5 years ago

The callback post data is definitely a bounce but seems like the code relies on $event->rcpt_meta->{'X-CiviMail-Bounce'} existing. In my testing I can receive data of a bounced email but $event->rcpt_meta->{'X-CiviMail-Bounce'} doesn't exist. So that means it skips the whole section where it records the bounce in CiviCRM.

I'm not sure why X-CiviMail-Bounce is empty now but I'll look into it, and also look into how to process bounces without depending on it. I would think it could since we clearly get the bounce information with the rest of the objects.

Here's a scrubbed sample of what's returned:

$sparkpost callback elements = array(1) {
  [0]=>
  object(stdClass)#319 (1) {
    ["msys"]=>
    object(stdClass)#320 (1) {
      ["message_event"]=>
      object(stdClass)#349 (29) {
        ["bounce_class"]=>
        string(2) "10"
        ["customer_id"]=>
        string(5) "26155"
        ["error_code"]=>
        string(3) "550"
        ["event_id"]=>
        string(18) "6255XXXXXXXXXXX"
        ["friendly_from"]=>
        string(15) "info@xxxxx.ca"
        ["initial_pixel"]=>
        bool(true)
        ["injection_time"]=>
        string(24) "2019-07-08T17:37:26.000Z"
        ["ip_address"]=>
        string(14) "XX.XXX.XXX.XXX"
        ["ip_pool"]=>
        string(6) "shared"
        ["message_id"]=>
        string(20) "0022XXXXXXXXXXXX"
        ["msg_from"]=>
        string(51) "msprvs1=18092XXXXXX=bounces-26155@mail.XXXXX.ca"
        ["msg_size"]=>
        string(4) "1220"
        ["num_retries"]=>
        string(1) "0"
        ["rcpt_meta"]=>
        object(stdClass)#321 (0) {
        }
        ["rcpt_tags"]=>
        array(0) {
        }
        ["rcpt_to"]=>
        string(16) "123@fakemail.com"
        ["raw_reason"]=>
        string(73) "550 5.1.1 <123@fakemail.com> Recipient not found.  <http://x.co/irbounce>"
        ["reason"]=>
        string(62) "550 5.1.1 ...@... Recipient not found.  <http://x.co/irbounce>"
        ["recv_method"]=>
        string(4) "rest"
        ["routing_domain"]=>
        string(12) "fakemail.com"
        ["sending_ip"]=>
        string(13) "XX.XX.XXX.XXX"
        ["subject"]=>
        string(13) "test bounce 2"
        ["template_id"]=>
        string(27) "template_625XXXXXXXXXXXXX"
        ["template_version"]=>
        string(1) "0"
        ["timestamp"]=>
        string(10) "1562607447"
        ["transactional"]=>
        string(1) "1"
        ["transmission_id"]=>
        string(18) "625XXXXXXXXXXXXX"
        ["type"]=>
        string(6) "bounce"
        ["raw_rcpt_to"]=>
        string(16) "123@fakemail.com"
      }
    }
  }
}
herbdool commented 5 years ago

An update: I think X-CiviMail-Bounce was empty because I was testing with a transactional email. Looks like this bounce processing only works with CiviMail and not sending individual emails. Either way Sparkpost records a bounce.

herbdool commented 5 years ago

I've created a PR to address that some properties and variables are undefined some times. For example, when an email is not being sent via CiviMail X-CiviMail-Bounce will not exist. And if there's no campaign then campaign_id doesn't exist. I separated the conditions so it's more understandable about when it will stop trying to process the bounce.

herbdool commented 5 years ago

@nganivet thanks for merging. Would you be able to create a new release for this and the other changes merged?