如何在文本中发送variables?

我能够发送静态电子邮件来修复修复内容的邮件标识,如何在nodemailer中使其dynamic化。

transporter.sendMail({ from: 'test@test.com', to: 'ashutosh.jha@mail.vinove.com', subject: 'Ashutosh Jha : credentials', text: 'hello how are you' }); 

几个选项。

 var body = 'Hello ' + name + ', how are you?'; var sprintf = require('sprintf-js').sprintf; var body2 = sprintf('Hello %s, how are you?', name); 

或者你可以使用像Swig或HandleBars这样的模板引擎。

现在正在工作谢谢你

 var mailcontent = ({ from: 'test@test.com', to: email, subject: 'AJ : credentials', html: 'Dear '+docs[0]['name'] + ',<br/><br/>here is your credentials : <br/><br/><br/><b> username :'+docs[0]['username']+'<br/> password : '+docs[0]['password']+'</b><br/><br/> Thanks and regards , <br/> AJ' }); transporter.sendMail(mailcontent , function(err , success){ if(err) { res.render('forget-password',{ error : err }); }else { res.render('index',{ success : 'Information succesfully sent to "' + email+'"' }); } });