Here I want to send a reply using Gmail API. For that, I got a successful response while retrieving. Now I have threadId using that threadId I need to send a reply instead of creating a new thread
This is my response for retrieval of mail
{
id: '178fe5f9cc632096',
threadId: '178fe5f9cc632096',
labelIds: [ 'IMPORTANT', 'CATEGORY_PERSONAL', 'INBOX' ],
snippet: 'it's working --',
payload: {
partId: '',
mimeType: 'multipart/alternative',
filename: '',
headers: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object]
],
body: { size: 0 },
parts: [ [Object], [Object] ]
},
sizeEstimate: 5218,
historyId: '119777',
internalDate: '1619175369000'
}
And my code for sending reply
function makeBody(to, from, subject, message) {
var str = ["Content-Type: text/plain; charset=\"UTF-8\"\n",
"MIME-Version: 1.0\n",
"Content-Transfer-Encoding: 7bit\n",
"to: ", to, "\n",
"from: ", from, "\n",
"subject: ", subject, "\n\n",
message
].join('');
var encodedMail = Buffer.from(str).toString("base64").replace(/\+/g, '-').replace(/\//g, '_');
return encodedMail
}
function sendMessage(auth) {
try {
var raw = makeBody('abc@gmail.com', 'xyz@gmail.com', 'test subject', 'workinggggggg...');
const gmail = google.gmail({ version: 'v1', auth });
gmail.users.messages.send({
auth: auth,
userId: 'me',
resource: {
raw: raw,
message_id: res.data.threadId
}
}, function (err, response) {
if (err) {
return console.log('The API returned an error: ' + err);
}
else
console.log(response)
});
} catch (error) {
console.log(error)
}
}
But while using this code a new thread is creating. Need help.