Generate HTML emails using templating engine (nunjuncks by default). Inspired by andrewrk/swig-email-templates.
<link rel="stylesheet">
s and the <style>
s.urlRewrite
option to rewrite your links.text: false
.var path = require('path');
var TplEmails = require("tpl-emails");
var emails = new TplEmails({
root: path.join(__dirname, "templates")
});
emails.render('meatball-sandwich.html', { context: { meatballCount: 9001 } }, function(err, html, text) {
// send html/text email
});
For example to use underscore/lodash templating engine:
var fs = require("fs");
var _ = require("lodash");
var TplEmails = require("tpl-emails");
var emails = new TplEmails({
render: function(tplname, context, callback) {
var content = fs.readFileSync("templates/"+tplname);
callback(null, _.template(content, context));
}
});
emails.render('meatball-sandwich.html', { context: { meatballCount: 9001 } }, function(err, html, text) {
// send html/text email
});