渲染html,以便发送nodemailer

时间:2017-05-17 00:13:28

标签: node.js express nodemailer

我尝试通过nodemailer发送邮件,但我想首先使用express渲染html以个性化邮件,例如添加用户名。我的代码是这样的:

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);
  });
});

但是emailHTML结果为null,我如何渲染模板并稍后发送?

0 个答案:

没有答案