How to Get SendGrid Alerts in Slack When WordPress Messages Bounce

Jacob Stimpson

Sendgrid alerts via zapier in slack

The Problem

On occasion, we’ve had an issue where a wpXPRESS member hasn’t received a critical email, such as the new order notification email sent by their WooCommerce estore. As you can imagine, that’s a big problem if they don’t receive that email! Some clients have forms that we built with Gravity Forms that are also critical. So I went searching for a solution. I thought for sure there must be a way we could get notifications when something went wrong.

Send WordPress Transactional Email with SendGrid

Our host, Flywheel uses SendGrid to handle all emails sent by sites hosted by them (one of many reasons they’re an incredible host). So all our sites send via SendGrid. We also have our own SendGrid account and run some of our client’s higher priority emails (such as WooCommerce notifications as mentioned) through our account, so we have more control and can see all the details if anything goes wrong. SendGrid tracks everything and makes it easy to see when an email bounces, is dropped or marked as spam. But it doesn’t alert anyone about these things. You’re forced to log in and review everything, including all the successful sends, just looking for the problems. For our small team, it’s just not reasonable for us to check regularly.

Get Notifications in Slack

Slack notificationSo the preferred solution to this problem seemed to be some kind of SendGrid integration that would alert us only when something was wrong. We already use UptimeRobot to alert us when one of our member’s sites goes down. It has a nice integration with Slack (our current team messaging app), so that we get an alert in one of our channels, anytime a site goes down. And we get that notification on our computers and phones. So one of us can always be aware when something goes wrong. That’s how we often fix issues with our member’s sites before anyone notices that there’s even a problem. I figured if we could do the same thing with SendGrid, we’d be good to go.

SendGrid’s Webhooks Don’t Work with Slack 🙁

SendGrid has a webhook notification function. So I grabbed a webhook URL from Slack and put it into SendGrid’s Event Notification function. But it wouldn’t work. Slack never posted any messages from the SendGrid webhook. I reached out to both Slack and SendGrid support. It turns out that the SendGrid webhook data isn’t formatted in a way that Slack understands, so it just does nothing.

Screen shot 2017 04 19 at 4.11.05 pm

Zapier to the Rescue

I did a bunch of research and some experimenting, but couldn’t find a way to make it work. Zapier seemed like the logical approach since it’s basically a middle-man to connect various apps and services. But it’s SendGrid integration only had 1 trigger for when a new list is added. I’m not even sure what that is, but it didn’t help me. I reached out to their support. Sam responded, suggesting that I try the Zapier webhook to get the data from SendGrid, then let Zapier reformat it and push it into Slack with their Slack integration.

So I tried it and it worked! Here’s how to do it:

  1. You’ll need to signup for or log in to Zapier and make a new Zap.
  2. Select “Webhooks by Zapier” for the trigger, then the “Catch Hook” option.
  3. Just select “Continue” on the “Pick off a Child Key” step. No need to enter anything.
  4. Next, it will provide a webhook URL. Copy it.
  5. Now login to your SendGrid account and go to Settings>Mail Settings.
  6. Now expand the “Event Notification” section and click “Edit”.
  7. Paste in the webhook URL you copied in step 4, to the “HTTP POST URL” space.
  8. Now check which actions you want to be notified on (I did Dropped, Bounced, and Mark as Spam).
  9. Hit the blue checkmark in the top-right to save and activate.
  10. Go back to Zapier and select “Okay, I did this” button.
  11. Now switch back to SendGrid again, and click the “Test Your Integration” button.
  12. Back in Zapier, it should say the test was successful, click the Continue button.
  13. Click the “Send Channel Message” option, then Save + Continue button.
  14. If needed, authorize access to your Slack account.
  15. Select which Slack channel you want the message posted to.
  16. Fill the “Message Text” with helpful info such as Email, Status, Reason, Timestamp, etc, by selecting the button on the right, and clicking available options from the drop-down. This is data fields that SendGrid is sending over. Mine is: “Sending error: event email reason | timestamp status sg_message_id category url”. URL is always sendgrid.com but makes it easier to get there quickly.
  17. If you want to, name the bot, and set an emoji for the icon.
  18. Finally, click the Create & Continue button. Whew! We’re almost there.
  19. It should say “Test Successful!” again. Click Finish.
  20. Now give the Zap a name, and turn it on by clicking the toggle switch. You’re done!
  21. But it’s a good idea to run a test by going to SendGrid and clicking that “Test Your Integration” button once more.

Video Walkthrough

If you’re a visual learner, here’s a step by step walkthrough from our YouTube Channel:

Too Technical or Don’t Have Time?

If this is too technical for you, sign up for one of our wpXPRESS WordPress support plans and we’ll connect your website to our SendGrid account and monitor any issues for you using the solution above. We monitor a bunch of other stuff too, so you can relax, knowing your website is working great!

You might also like these blogs and articles

4 Comments

  1. Ben CHARLTON

    Great Post – and I learnt how powerful Zapier is as an integration in Slack

    Am

    Reply
  2. Alex

    Hello, is it possible to trigger the event with a singe sendgrid email rather than all my sendgrid emails?

    Reply
    • Tevya

      Great question Alex! You should ask Zapier support. I’m not sure.

  3. Thib

    This was super helpful. Thank you!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Our Newsletter for Updates

Stay in the loop and receive exclusive offers!

"*" indicates required fields

Name*
Hidden
Privacy*