webhookssendgrid

How to associate sendgrid webhook sg_message_id to sent mail?


Sendgrid webhook has sg_message_id But the response of Web API v2 when sending mail doesn't have sg_message_id. In fact, there is only message showing only success or failed.

So, how do i associate between sent mail and the webhook callback?

I have check the past questions in SO but it doesn't provide be the solution for this.

Thank you.


Solution

  • You can use unique arguments. Take your unique ID (like primary key) and give it to sendgrid API during sending email. You will get it back in the event webhook.

    https://docs.sendgrid.com/for-developers/sending-email/unique-arguments

    When you want to use "unique arguments" through SMTP you should be able to do so using the X-SMTPAPI message header.

    https://docs.sendgrid.com/for-developers/sending-email/building-an-x-smtpapi-header