如何在文本中发送变量?

How to send variable in text?

我可以发送静态电子邮件来修复邮件 ID 和固定内容,如何在 nodemailer 中使其动态化。

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 or 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+'"'
                    });     
                }
            });