问题:
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.