Google-api-nodejs-client: gmail.users.drafts.create - 'In-Reply-To' and 'References' Headers not setting

Created on 16 Jan 2020  路  6Comments  路  Source: googleapis/google-api-nodejs-client

Environment details

  • OS: macOS Catalina 10.15.1
  • Node.js version: 11.14.0
  • npm version: 6.13.4
  • googleapis version:46.0.0

Issue

Gmail threads fine from the sender's account but doesn't thread in the recipient's gmail account.

Steps to reproduce

  1. First tried adding the headers in the payload object
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)
  1. Then tried adding the headers to the MIME encoded message itself
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!

question

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.

All 6 comments

@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:

  1. making sure threadId matches this format.
  2. try setting threadId without the headers.
  3. if this doesn't work, try dropping the <, and > from the headers, I would guess that the API inserts this for you.

@bcoe

  1. I set the 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?

  1. threadId without the headers doesn't do it either. That's why I tried adding the headers to the payload.

  2. 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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raapperez picture raapperez  路  3Comments

oliverjessner picture oliverjessner  路  3Comments

ACMerriman picture ACMerriman  路  3Comments

eduDorus picture eduDorus  路  3Comments

skiod picture skiod  路  3Comments