【发布时间】:2020-11-07 03:40:24
【问题描述】:
我正在使用nodemailer 为注册用户发送电子邮件。函数如下:
const setAndSendMsg = (recipients, users, subject, template) => {
const htmlFile = checkTemplate(template)
const message = {
from: mailServer.mailerObj.auth.user,
bcc: recipients,
subject: subject,
// html: `<div><b>Hello</b></div>`,
html: htmlFile,
context: {
user: 'test'
}
}
transport.sendMail(message, function(err, data) {
if(err) {
console.log(err);
return err
} else {
console.log(data);
return data
}
})
}
checkTemplate返回所需模板:
const checkTemplate = (template) => {
return fs.readFileSync(path.resolve(__dirname, `../email-templates/${template}.html`), 'utf-8').toString()
}
模板包含:
<div>
Dear {{user}},
<br/>
<div>
Welcome to our platform, please click on the link below to activate your account:
</div>
</div>
所有收件人都收到了这封电子邮件,如下所示:
亲爱的{{user}},...
没有显示test 代替{{user}}
我在 stackoverflow 上使用了来自 question 的脚本,但它不起作用。
【问题讨论】:
-
你使用的模板引擎是什么?
-
@Bibek 普通 html
标签: node.js express nodemailer