googleapis version:46.0.0Gmail threads fine from the sender's account but doesn't thread in the recipient's gmail account.
const msgId = // Some gmail message id
const mimeDraftEncodedMessage = base64url(`To:[email protected]\r\n` +
`From:[email protected]\r\n` +
`Subject:sample subject\r\n` +
`Content-Type: text/html; charset=utf-8\r\n` +
`MIME-Version: 1.0\r\n\r\ntest message`;)
const params = {
userId: 'me',
requestBody: {
message: {
raw: mimeDraftEncodedMessage,
threadId,
payload: {
headers: [
{ name: 'In-Reply-To', value: `<${msgId}>` },
{ name: 'References', value: `<${msgId}>` },
],
},
},
},
}
gmail.users.drafts.create(params)
const msgId = // Some gmail message id
const mimeDraftEncodedMessage = base64url(`To:[email protected]\r\n` +
`From:[email protected]\r\n` +
`Subject:sample subject\r\n` +
`In-Reply-To:${msgId}\r\n` +
`References:${msgId}\r\n` +
`Content-Type: text/html; charset=utf-8\r\n` +
`MIME-Version: 1.0\r\n\r\ntest message`;)
const params = {
userId: 'me',
requestBody: {
message: {
raw: mimeDraftEncodedMessage,
threadId,
},
},
}
gmail.users.drafts.create(params)
Any help would be greatly appreciated. Thanks!
@e1um have you checked the raw email content in the recipients account to verify the headers are present?
@bcoe yea I checked through the 'show original' and the headers aren't there. Is there something I'm missing so that the headers go through? It's definitely in the MIME message before I encode it. Thanks!
what is the value of threadId, in the docs I notice:
The References and In-Reply-To headers must be set in compliance with the RFC 2822 standard
I recommend:
threadId matches this format.threadId without the headers.<, and > from the headers, I would guess that the API inserts this for you.@bcoe
threadId to the threadId that gmail gives in response to gmail.users.drafts.create(params) . I believe this is how I'm able to get threading on the sender side. I couldn't find a reference to 'threadId' in RFC 2822. What I gathered from RFC 2822 is that the References and In-Reply-To headers should be set to the messageId that the new draft is replying to (to help with threading?). What I'm unsure of is if the messageId that gmail provides is the same as the global messageId?
threadId without the headers doesn't do it either. That's why I tried adding the headers to the payload.
Yea tried it without the < and >
Really appreciate the help! I feel like I've tried everything and still can't move the needle on this...
Thanks, I finally figured this out. This post was super helpful - https://stackoverflow.com/questions/32589476/how-to-send-a-reply-with-gmail-api/32591614#32591614
Probably not your job, but I think the gmail api guides should make a better distinction between gmail 'msgId' and the 'Message-Id' from the headers.
@e1um awesome, I'm glad you figured this out :+1:
Most helpful comment
Thanks, I finally figured this out. This post was super helpful - https://stackoverflow.com/questions/32589476/how-to-send-a-reply-with-gmail-api/32591614#32591614
Probably not your job, but I think the gmail api guides should make a better distinction between gmail 'msgId' and the 'Message-Id' from the headers.