handlebars.js - How to use handlebars with nodemailer to send email? -
i using nodemailer send emails using following nodemailer-express-handlebars plugin. used blog post reference
the code compiling welcome
template not using layout
my code below:
var nodemailer = require('nodemailer'); var mg = require('nodemailer-mailgun-transport'); var hbs = require('nodemailer-express-handlebars'); var config = {auth: {api_key: "key-xxx",domain: "mydomain.com}} var nodemailertransport = nodemailer.createtransport(mg(config)); var options = { viewengine: { extname: '.handlebars', layoutsdir: 'views/email/', defaultlayout : 'layout', }, viewpath: 'views/email/' } nodemailertransport.use('compile', hbs(options)); nodemailertransport.sendmail({ from: 'from@mydomain.com', to: 'to@gmail.com', subject: 'welcome xxx', template: 'welcome' }, function (err, results) { if (err) console.log('error: ' + err); else console.log('response: ' + results); });
my layout.handlebars
has following code
<html> <body> {{> _header }} {{{body}}} {{> _footer }} </body> </html>
Comments
Post a Comment