Hey, this is a plugin for Nodemailer that renders email templates using Swig. Includes in templates works, images and attachments and other stuff to come in future. Inspired by nodemailer-express-handlebars. Find it NPM.
npm install node-paperboyvar path = require('path');
var paperboy = require('node-paperboy');
var options = {
viewPath: path.resolve(__dirname, '../path/to/templates'),
extName: 'html',
cidFolder: 'img'
}
// Use the plugin with the Nodemailer transport instance.
transporter.use('compile', paperboy(options));
var mail = {
from: 'from@foo.tld',
to: 'to@foo.tld',
subject: 'A good Email',
template: 'TemplateFile.html',
attachments: [{
filename: 'test.ogg',
content: '/where/is/my/file.ogg'
}]
}
transporter.sendMail(mail, cb);The plugin expects the following options:
- viewPath (required) The path to the directory where your templates live.
- extName (optionnal) The extension of the template to use (defaults to 'html').
- cidFolder (optionnal) The folder who content image for template, must be present in same folder of templates
Set the template and values properties on the mail object before calling sendMail
- template The name of the template file to use.
- context (optionnal) The data to pass to your email template.
- attachments (optionnal) An array of attachments file
MIT