5

I am using nodemailer to send emails. But I would like to send reply to a mail (start a new thread).I have tried sending reply to a mail using the below code

var nodemailer = require('nodemailer');

const subject = 'Hey I am test';

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '*******',
    pass: '*******'
  }
});

const mailOptions = {
  from: 'mymail@gmail.com',
  to: 'receiver@gmail.com',
  subject,
  text: 'Body',
};

transporter.sendMail(mailOptions, function (error, info) {
  if (error) {
    console.log(error);
  } else {
    console.log(info.messageId);
    const threadOptions = {
      from: 'mymail@gmail.com',
      to: 'receiver@gmail.com',
      subject:'Re: ' + subject,
      text: 'This is reply',
      inReplyTo: info.messageId,
      references: [info.messageId]
    };
    transporter.sendMail(threadOptions);
  }
});

But it is sending as a new mail. It was mentioned in the doc using inReplyTo and references fields will start a new thread. But it is not working

Any little help would be really thankful

Willian
  • 2,098
  • 1
  • 9
  • 34
Nikhil Ponduri
  • 290
  • 6
  • 19
  • Are you trying to setup an autoreply system? I mean, firstly a user sends you a message, and then you send an automatic reply? Could you please describe the scenario a bit more? – Towerss Jul 05 '20 at 06:57

1 Answers1

0

After research a lot, I think this link can help: https://stackoverflow.com/a/2429134/8270395. And look at this as well: Sending an email to myself but letting me reply back to another email.

Hope this help.

ShinaBR2
  • 2,140
  • 1
  • 9
  • 21