node.js - 电子邮件模板/Nodemailer 电子邮件不包含模板
问题描述
我正在尝试发送一个 ejs 模板,email-templates
但我并没有很高兴。
电子邮件发送正常,但不包含任何模板数据。
const email = new Email ({
template: 'activateAccount',
message: {
from: "noreply@domain.com",
subject: "Activate your account!",
to: data.email
},
locals: {
name: data.name,
url: data.url
},
send: true,
transport: {
host: "domain.com",
port: 2525,
auth: {
user: "abc",
pass: "123"
}
},
views: {
options: {
extension: 'ejs'
}
}
});
return await email.send();
有谁知道为什么没有填充模板?
解决方案
使用locals
when.send
发送电子邮件,
const email = new Email({
message: {
from: "noreply@domain.com",
subject: "Activate your account!",
to: data.email
},
send: true,
transport: {
host: "domain.com",
port: 2525,
auth: {
user: "abc",
pass: "123"
}
},
views: {
options: {
extension: 'ejs'
}
}
});
await email.send({
template: 'activateAccount',
locals: {
name: data.name,
url: data.url
}
});
基本上,您可以使用的所有选项都是.send
函数本身。
推荐阅读
- docker - 如何从 Azure Key Vault 获取证书以在 docker 映像中使用
- c++ - 我可以限制多态性的行为吗?
- python - 如何在类中使用多处理必须属性是对象和字典?
- html - 视频上的 Firefox 混合模式错误 (mac)
- vb.net - 通过 VLAN 发送短信
- python - 如何将平均线添加到 seaborn stripplot 或 swarmplot
- tensorflow - 具有未知形状输入的自定义 Keras 损失函数
- webview - 在 Kotlin Android 中阅读 webview 内容
- c# - 是否可以在事件查看器中使用 ETW 登录到子文件夹时使用自定义名称创建事件通道?
- c# - 如何在asp.net web api中将图像路径转换为http url?