我想在用户注册后发送一封感谢邮件,但我不知道如何将用户名传递给我的电子邮件模板。我有以下代码:
app.mailer.send('email', {
to: 'newuser@gmail.com', // REQUIRED. This can be a comma delimited string just like a normal email to field.
subject: 'Test Email', // REQUIRED.
user: req.body.user, // All additional properties are also passed to the template as local variables.
}, function (err) {
if (err) {
// handle error
console.log(err);
res.send('There was an error sending the email');
return;
}
res.send('Email Sent');
});
电子邮件模板:
<html>
<head>
<title>{{subject}}</title>
</head>
<body>
Thank you {{user}}
</body>
</html>
答案 0 :(得分:2)
您可以将属性传递给请求。
{
to: 'newuser@gmail.com', // REQUIRED. This can be a comma delimited string just like a normal email to field.
subject: 'Test Email', // REQUIRED.
username: req.body.username,
myVar: 'username'
}
变量myVar
作为局部变量传递给模板