将本地值传递给电子邮件模板使用Express-Mailer

我想在用户注册后发送一封感谢电子邮件,但我不知道如何将用户名传递给我的电子邮件模板。 我有以下代码:

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> 

您可以将属性传递给请求。

{ 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' }

variablesmyVar作为局部variables传递给模板