nodemailer-mjml-mustache
A plugin for nodemailer that uses mjml and mustache view engine to generate emails.
Installation
npm install nodemailer-mjml-mustache --save
Plugin Options
viewPath
(required) provides the path to the directory where your views are
Mail Options
template
the name of the template file to use without the extensioncontext
this will be passed to the view engine as the context data to render the variables with.
context: {
name: `Bob Ross`,
url: `https://mjml.io/try-it-live`,
}
<mj-text>Hello {{name}}, <a href="{{url}}">Click here</a></mj-text>
Example Usage
let nodemailer = require(`nodemailer`)
let mjml = require(`../lib`)
let htmlToText = require(`nodemailer-html-to-text`).htmlToText
let transporter = nodemailer.createTransport({
host: '127.0.0.1',
port: 1025,
})
transporter.use(`compile`, mjml({
viewPath: `${__dirname}/views`
}))
transporter.use(`compile`, htmlToText())
const options = {
context: {
name: `Bob Ross`,
url: `https://mjml.io/try-it-live`,
},
from: `from@email.com`,
to: `to@email.com`,
subject: `Verify your email address`,
template: `example`,
}
console.log("Sending options", options)
new Promise((resolve, reject) => {
transporter.sendMail(options, function(error, info){
if (error) {
return reject(error)
}
resolve(info)
})
})