Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot start a mail thread (reply to a mail) using nodemailer (gmail)

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: '[email protected]',
  to: '[email protected]',
  subject,
  text: 'Body',
};

transporter.sendMail(mailOptions, function (error, info) {
  if (error) {
    console.log(error);
  } else {
    console.log(info.messageId);
    const threadOptions = {
      from: '[email protected]',
      to: '[email protected]',
      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

like image 256
Nikhil Ponduri Avatar asked Nov 15 '22 09:11

Nikhil Ponduri


1 Answers

  1. Subject of reply mail should be same as Subject of mail sent. When Subject of reply mail and mail to which you have replied are same then reply mail will be in thread of previously sent mail.

  2. You have to define credentials for email account from which you are replying

Sorry for my bad English

like image 81
Fahad Avatar answered Dec 15 '22 00:12

Fahad