SendGrid API v3: Reply to a thread

2.3k Views Asked by At

I am trying to send an email as a reply to a previous thread using SendGrid v3 APIs. But it always shows as a new email thread in Outlook. I am using "Message-ID", "In-Reply-To" and "References" fields but it always fails to show under single thread. I am referring this thread here to set the headers.

SendGrid document doesn't specify if v3 supports replying to previous thread or not. Any way to achieve email thread conversation is appreciated.

2

There are 2 best solutions below

3
On BEST ANSWER

OKAY. I figured out the key here. I was missing "<>"angled brackets and looks like SendGrid takes it very seriously. So this is how headers section should look like.

"headers": {
    "Message-ID": "<[email protected]>",
    "In-Reply-To": "<[email protected]>",
    "References": "<[email protected]>"
}

Checkout the angled brackets surrounding header values.

0
On

A was struggling with this same issue, so here is my solution overview - hope it helps!

How do you find Message-ID in the first place?

You can specify this when you send email via SendGrid 'send' API. Example POST call's JSON body could look like:

{"personalizations":[{"to":[{"email":"[email protected]","name":"John Doe"}],"subject":"Email title"}],"content": [{"type": "text/plain", "value": "Heya!"}],"from":{"email":"[email protected]","name":"myname"},"reply_to":{"email":"[email protected]","name":"myname"},"headers": {
"Message-ID": "<[email protected]>"}}

To be frank, I do not yet know the limitations for the "Message-ID" structure or formatting, but you can take a look at examples from other emails you receive e.g. in gmail "show original message" >> "Message-ID"

Now, when you want to send email as a reply to the previous one, your POST call's body could look like this:

{"personalizations":[{"to":[{"email":"[email protected]","name":"John Doe"}],"subject":"Email title"}],"content": [{"type": "text/plain", "value": "This is my reply!"}],"from":{"email":"[email protected]","name":"myname"},"reply_to":{"email":"[email protected]","name":"myname"},"headers": {
"Message-ID": "<[email protected]>",
"In-Reply-To": "<[email protected]>",
"References": "<[email protected]>"}}

Happy to hear more details/ideas around this!

P.S. A couple confusing things I ran into:

  • SendGrid does not provide documentation around this!
  • Message-ID is not the same as SendGrid's internal message ID, used for tracking email events and activity feed.
  • Nor should you mix Message-ID with x-message-id, as I did, that you receive in API response's header when you send an email.

Best of luck!