In a rush? Here’s the bottom line
The Problem 🤷♂️
I’ve recently had to write an integration with SendGrid, an email sending service by Twillio. SendGrid’s API is very straightforward, and so development went quickly, but when it came time to test that everything is working correctly something strange happened - my email was not getting delivered.
The Despair 😭
I tried to debug the issue, but because SendGrid works asynchronously, my API calls would all return 202 Accepted, meaning my message has been entered into the send queue and will be processed. That meant that my request was passing initial validation, but some error was happening internally later. The API responses did not include any information that could be used to understand what was going on.
I spent a considerable amount of time trying to understand where I can see these kinds of errors, but the SendGrid UI did not contain anything useful in that regard. The dashboard shows the number of errors, but it presents delayed information, and there’s no way to see detailed information anyway, so that’s was not useful as well.
I admit I was getting quite frustrated.
The Solution ❗
While skimming through the API documentation trying to find a solution, I noticed that there’s support for Webhook event reporting. I wasn’t sure what information is sent for each event, but I figured if I enable all event types I’m bound to see something. So here’s the solution -
- Go to RequestBin.com and create a new endpoint. You will be redirected to the inspection page, where you can see any requests made to that endpoint. Copy your endpoint URL.
- Inside the SendGrid dashboard, go to
Settings>Mail Settings>Event Notification, paste the endpoint address from RequestBin into the “HTTP POST URL” field and enable all action types, then turn “Event Notification” on using the toggle.
Now try sending your email message again - you should see detailed information showing up in the RequestBin page almost immediately. The event to look for if your messages are not arriving is the dropped event. In my case, the template I was trying to use was not enabled, which was causing a “The template id must be a valid template id for your account” error to be thrown .
I hope you found this helpful, and may all your email’s arrive at their destination swiftly 😉