我正在尝试使用SendGrid发送电子邮件,并且正在为不同情况准备多个模板。我的函数如下所示:
var file = "welcome.html"
sendgrid.send({
to: to,
from: from,
subject: subject,
data: {
//template vars go here
email: to,
confirmLink: confirmLink
},
template: "./" + file
}, function(err, json) {
if (err) { return console.error(err); }
console.log(json);
});
但是当我发送邮件时,出现以下问题:
[Error: Missing email body]
有没有办法附加HTML模板,因为我不想使用硬编码的字符串来包含HTML内容?
编辑
读取并将文件转换为字符串可行,但我不确定如何将动态变量传递到模板中...
有什么建议吗?