I'm trying to set up a confirmation email which is launched from Expressjs. This email template is in html (now ejs) and I need to pass variables to it so I can later save in a variable and send it with nodemailer.
Im trying to do something like this whitout success:
var final_html = res.render('confirm', {variables: 'aasdad'});
NodeMailer code:
var mailOptions = {
from: test@test.com, // sender address
to: 'test@test.com', // list of receivers
subject: 'Welcome '+req.body.name, // Subject line
html: final_html
};
How can achieve this?
Thanks in advance!
PD: Post answer code:
var final_html = res.render('confirm', {url: 'aasdad'}, function(err, html) {
if (err){ return err;}
return html;
});
Just pass in a callback as a third argument and it will get called with (err, final_html):
res.render('confirm', {variables: 'aasdad'}, function(err, final_html) {
if (err) throw err; // TODO: handle errors better
var mailOptions = {
from: 'test@test.com', // sender address
to: 'test@test.com', // list of receivers
subject: 'Welcome ' + req.body.name, // Subject line
html: final_html
};
// call node-mailer with `mailOptions` here ...
});