SendGrid API v3: Reply to a thread
Asked Answered
F

2

7

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.

Fireside answered 19/12, 2021 at 22:57 Comment(0)
F
10

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.

Fireside answered 20/12, 2021 at 2:34 Comment(3)
It's also picky about the subject fieldDistillation
Another scenario I recommend testing: Responding to forwarded emails and not just ones replied to.Distillation
Does anyone know where can I get the message-id? It's not included in the v3 API response,Nepheline
G
2

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!

Gonad answered 26/1 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.