0

I have full response of a email send using node module google-api-nodejs-client, which is like { "id": "1231212312", "labelIds": ["UNREAD", "SENT", "INBOX"], "threadId": "23123123" }

I need to send an email again to the email address but in the same thread not as a new email.

I checked the documentation but wasn't able to find relevant stuff.

Here is the link to its documentation: https://github.com/google/google-api-nodejs-client/blob/master/apis/gmail/v1.js#L796

Thanks!

Deepak
  • 37
  • 2
  • 11

1 Answers1

0

In order to make your message display in the same thread you need to make it RFC compliant which means you need to add the In-Reply-To and References header that includes the Message-ID (also a header) of the previous message.

Afterwards, you can then provide the threadId to the Gmail API which will then send it as the same thread. Gmail also requires that your "subject" be the same as the previous message.

References:

Steven Lu
  • 2,150
  • 1
  • 24
  • 33
  • so instead of 'To' i need to add 'In-Reply-To' and References : messageId i.e ```email_lines.push(`From:${user_account.email}`); email_lines.push(`In-Reply-To:${contact_email}`); email_lines.push(`References: '15a5236d11e3bb65'`); email_lines.push('Content-type :text/html;charset=iso-8859-1'); email_lines.push('MIME-Version:1.0');``` and ```gmail.users.messages.send({ auth: oauth2Client, 'userId': 'me', 'threadId': '15a5236d11e3bb65', 'resource': { 'raw': base64EncodedEmail } ``` Right ? Some thing like this ? – Deepak Feb 18 '17 at 17:21
  • You still need the To header, you just need to apply the other headers also. Referenes and In-Reply-To need to match the Message-ID header of the previous message. – Steven Lu Feb 18 '17 at 17:37
  • An example of that Message-ID is `` – Steven Lu Feb 18 '17 at 17:37
  • {"id": "15a5236d11e3bb65", "labelIds": ["UNREAD", "SENT", "INBOX"], "threadId": "15a5236d11e3bb65"} so using this response -> Id@mail.gmail.com is my message id right ? – Deepak Feb 18 '17 at 17:44
  • No, you need to obtain the message after you send it using the id of your response. Then in the headers of the message you just sent you'll need find "message-id" and obtain that. This is the RFC 2822 header that you need to obtain. – Steven Lu Feb 18 '17 at 18:02
  • Got it. Thank you. :) – Deepak Feb 18 '17 at 18:15
  • I am getting permission issue while i am obtaining message id, can you let me know which permission is required ? – Deepak Feb 18 '17 at 19:02