Template nordemailer with twig

问题: I want to template an email with nodemailer and twig. How can I do it? My code: var messages = { from: "XX", to: "XX", subject: objet, text: Twig.render...

问题:

I want to template an email with nodemailer and twig. How can I do it?

My code:

var messages = {
    from: "XX",
    to: "XX",
    subject: objet,
    text: Twig.renderFile('mail.twig',{message: mess}),
    attachments:[
        {
            filename: url_facture.facture_id + '.pdf',
            content: resultat
        }
    ]
};

回答1:

Reading the Twig documentation, it seems that the renderFile method is async and require a callback.

There are several approaches to handle async functions. The fastest thing you could do is:

Twig.renderFile('mail.twig', {message: mess}, function(err, html){
    var messages = {
        from: "XX",
        to: "XX",
        subject: objet,
        text: html,
        attachments:[
            {
                filename: url_facture.facture_id + '.pdf',
                content: resultat
            }
        ]
    };
})

You can also consider using a Promise in combination with async/await commands.

  • 发表于 2019-02-27 20:41
  • 阅读 ( 164 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除