如何在文本中发送变量?

时间:2015-12-28 10:12:36

标签: node.js express ejs nodemailer

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

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

2 个答案:

答案 0 :(得分:3)

一些选择。

var body = 'Hello ' + name + ', how are you?';

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

或者您可以使用SwigHandleBars等模板引擎。

答案 1 :(得分:0)

它现在正在工作

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