【发布时间】:2020-06-16 23:31:47
【问题描述】:
在我的应用程序中,我设置了 nodemailer 来发送电子邮件。该应用程序是使用 Vue 和 Firebase 构建的。 我需要从 UI 修改电子邮件模板,因此它们以 HTML 格式保存在数据库中。 在这些模板中,我需要能够使用动态值。
这是创建电子邮件的方法:
const mailOptions = {
from: "Test",
to: req.body.email,
subject: "New email from" + " " + req.body.email,
html: req.body.arenile.email_template
};
FireStore中req.body.arenile.email_template的内容是:
<p>Date: ${req.body.reservation_date} </p><p>Email: ${req.body.email}</p>
问题是变量没有按原样评估和打印在电子邮件中。
我试过了:
html: ` ${req.body.arenile.email_template}`
但它并没有解决它。
如果我使用:
html: `<p>Date: ${req.body.reservation_date} </p><p>Email: ${req.body.email}</p>`
它工作正常。 ${req.body.email} 打印为email@example.com
但是:
html: ` ${req.body.arenile.email_template}`
没有。 ${req.body.email} 打印为${req.body.email}
我不确定是否需要以不同的方式转义 HTML,或者是否在错误的位置评估请求数据..
我该如何解决?
【问题讨论】:
-
你试过
html: req.body.arenile.email_template而不是html: ` ${req.body.arenile.email_template}`吗? -
是的,结果相同
-
控制台有输出吗? (或尝试
console.dir(req.body.arenile.email_template))
标签: javascript nodemailer