Reputation: 51
I want to send a thank you email after user sign up but i don't know how to pass username to my email template. I have the following code:
app.mailer.send('email', {
to: '[email protected]', // 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');
});
email template:
<html>
<head>
<title>{{subject}}</title>
</head>
<body>
Thank you {{user}}
</body>
</html>
Upvotes: 5
Views: 714
Reputation: 1908
You can pass properties to the request.
{
to: '[email protected]', // 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'
}
The variable myVar
is passed as local variable to the template
Upvotes: 2