I am sending emails via sendgrid and would like to track the status of an email.
client = sendgrid.SendGridClient(username_or_apikey=my_key)
msg = sendgrid.Mail()
msg.add_to('[email protected]')
msg.set_html('<div> hello there </div>')
msg.set_from('[email protected]')
msg.set_subject('test sendgrid subject')
resp = client.send(msg)
The response object I am getting back is simply (200, '{"message":"success"}')
. I was hoping to get back some for of email id.
I know sendgrid has webhooks, but how do I associate a sg_message_id
with an email that I sent?
You can generate unique arguments on a per mail basis that go into the SMTP API JSON string and are included in status messages to webhooks.
Updated documentation URL from Todd M's answer:
https://docs.sendgrid.com/for-developers/sending-email/building-an-x-smtpapi-header
(Old Docs URL) More info at this page: https://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html