This plugin works with nodemailer 6.x. And uses the express-handlebars view engine to generate html emails.
npm install nodemailer-express-handlebars
//reference the plugin
import hbs from 'nodemailer-express-handlebars';
//attach the plugin to the nodemailer transporter
transporter.use('compile', hbs(options));
//send mail with options
const mail = {
from: 'from@domain.com',
to: 'to@domain.com',
subject: 'Test',
template: 'email',
context: {
name: 'Name'
}
}
transporter.sendMail(mail);
You can send a multipart html and text email by setting the text_template
option on a mail message.
const mail = {
from: 'from@domain.com',
to: 'to@domain.com',
subject: 'Test',
template: 'email',
text_template: 'text',
context: {
name: 'Name'
}
}
The plugin expects the following options:
.handlebars
)Set the template and values properties on the mail object before calling sendMail
MIT