Tuesday 16 May 2017

Render html so send nodemailer

I trying to send a mail via nodemailer but I would like to render first the html with express to personalize the mail like adding the username. I have my code like this:

user.save()
  .then(function() {
    req.login(user, function(err) {
      //blah blah
    });
  })
  .catch(function(err) {
    //blah blah
  });

res.render(path.resolve('modules/users/server/templates/welcome-password-email'), {
  name: user.displayName,
  appName: config.app.title,
  url: 'http://' + req.headers.host
}, function(err, emailHTML) {
  var mailOptions = {
    to: user.email,
    from: config.mailer.from,
    subject: 'Welcome',
    html: emailHTML
  };

  smtpTransport.sendMail(mailOptions, function(error, info) {
    if (error) {
      return console.log(error);
    }
    console.log('Message sent: ' + info.response);
  });
});

But the emailHTML result to be null, how do I render the template and send it later?



via Ellebkey

No comments:

Post a Comment