如果电子邮件与之前发送的电子邮件具有相同的主题,则 Nodemailer 会将电子邮件作为线程发送。但我想将这些电子邮件作为单独的电子邮件发送,即使它们的主题相同。
我有一个向用户发送通知电子邮件的应用程序。这些电子邮件都有相同的主题:通知。这导致电子邮件显示为线索,至少在 Gmail 中是这样:
如何让每封通知电子邮件单独发送?
const nodemailer = require('nodemailer');
const logger = require('./logger');
class Email {
constructor(email, to, pass) {
this.user = email;
this.to = to;
this.pass = pass;
}
get mailOptions() {
return {
from: this.user,
to: this.to,
subject: 'notification',
html: 'You received a new purchase in your shop.',
};
}
get transporter() {
const transporter = nodemailer.createTransport({
// for zoho emails
host: 'smtp.zoho.com',
port: 587,
secure: false,
auth: {
user: this.user,
pass: this.pass,
},
});
return transporter;
}
send(cb) {
this.transporter.sendMail(
this.mailOptions,
cb ||
((error, info) => {
if (error) console.log(error);
if (info) logger.log('silly', `message sent: ${info.messageId}`);
this.transporter.close();
})
);
}
sendSync() {
return new Promise((res, rej) =>
this.transporter.sendMail(this.mailOptions, (error, info) => {
if (error) rej(error);
else res(info);
this.transporter.close();
})
);
}
}
const email = new Email(
'[email protected]',
'[email protected]',
'SendINgEmAIlPassWoRD'
);
email.send();
在邮件选项的标头中使用带有随机值的参考属性。例如:
const mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'This is a test email',
text: 'This is the body of the email.',
headers: {
References: '<unique-reference-id>'
}
};