const nodemailer = require('nodemailer');
var transporter = null;
nodemailer.createTestAccount((err, account) => {
// create reusable transporter object using the default SMTP transport
transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: 'xxxx@example.com', // generated ethereal user
pass: 'xxxxx' // generated ethereal password
}
});
});
var mailOptions = {
from: "'test'<test@test.com>"
to: mail, // list of receivers
subject: subject, // Subject line
html: '<p>test</p>' ,
attachments : []
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return res.send(500);
}
console.log('Message sent: %s', info.messageId);
return res.send('ok');
});
以上代码是我发送电子邮件的实现,此代码完美无缺,我可以收到一封电子邮件,但问题是来自 电子邮件地址的 没有变化根据我的邮件选项。它始终从我在传输器用户中使用的电子邮件地址获取邮件。
auth: {
user: 'xxxx@example.com', // generated ethereal user
pass: 'xxxxx' // generated ethereal password
}
可能是什么问题。我尝试将电子邮件更改为所有其他有效的电子邮件。
我提到: Nodemailer with Gmail "From: address" does not change
无法获得任何信息。