spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

Distinction PermanentBounce and Blocked email with Sendgrid #239

Closed electronick86 closed 3 years ago

electronick86 commented 3 years ago

Hello!

During the migration of lists from an old system to Mailcoach, we have to manage the IP warmup process with our new email service provider. In our case : Sendgrid.

We have problems when Microsoft mails servers reject our messages due to IP reputation. The answer Sendgrid get is 550 5.7.1 Unfortunately, messages from [w.x.y.z] weren't sent. Please contact your Internet service provider since part of their network is on our block list (S3150). You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors. [AM6EUR05FT064.eop-eur05.prod.protection.outlook.com]"

Based on that, Sendgrid forward that to us with the following payload :

   {
      "email":"___@hotmail.com",
      "event":"bounce",
      "ip":"xxx",
      "reason":"550 5.7.1 Unfortunately, messages from [w.x.y.z] weren't sent. Please contact your Internet service provider since part of their network is on our block list (S3150). You can also refer your provider to http:\/\/mail.live.com\/mail\/troubleshooting.aspx#errors. [DM6NAM11FT044.eop-nam11.prod.protection.outlook.com]",
      "send_uuid":"c3c87e09-8063-4d13-8bf8-e8254c06b8ed",
      "sg_event_id":"Ym91bmNlLTAtMTY4NDUzNDMtSVdlLXN0RFhTUC05eWJNekpWY19QQS0w",
      "sg_message_id":"IWe-stDXSP-9ybMzJVc_PA.filterdrecv-p3iad2-5b55dcd864-pbk2w-17-5EF98383-10E.0",
      "smtp-id":"<a67c8a7465744e6312bae0aae8680cfd@swift.generated>",
      "status":"5.7.1",
      "timestamp":1593410436,
      "tls":0,
      "type":"blocked"
   }

This is "catched" as a Permanent Bounce with

class PermanentBounceEvent extends SendgridEvent
{
    public function canHandlePayload(): bool
    {
        return $this->event === 'bounce';
    }
...
}

This marked my subscribers as unsubscribed and it was quite complex to resubscribe those subscribers afterwards.

It could be nice to make a distinctions between Bounced and Blocked. As described in the Sendgrid Event Webhook Reference,

Bounce Receiving server could not or would not accept mail to this recipient permanently. If a recipient has previously unsubscribed from your emails, the message is dropped. "event":"bounce", "type":"bounce"

Blocked Receiving server could not or would not accept the message temporarily. If a recipient has previously unsubscribed from your emails, the message is dropped. "event":"bounce", "type":"blocked"

riasvdv commented 3 years ago

We could adapt the check to $this->event === 'bounce' && $this->type === 'bounce';

You won't get any overview of "blocked" messages in Mailcoach though, as different providers handle them in different ways, but at least your subscribers won't be unsubscribed

What do you think about this?

electronick86 commented 3 years ago

Hi Rias.

I think this check is way better. We just have to keep an eye on the deliverability stats on Sendgrid, especially during the migration/IP warmup process.

In the future, theses blocks could appear in a Mailcoach Campaign Report (in fact, the block event could just do an increment of a counter in the mailcoach_campaignstables).

riasvdv commented 3 years ago

This is fixed in version 2.2.5 of the sendgrid package: https://github.com/spatie/laravel-mailcoach-sendgrid-feedback/releases/tag/2.2.5