node-html-emails
Localized HTML email templates for node.
- Uses Handlebars as templating engine
- Makes localization with i18n
- You can write your own css file which will be inlined with juice
Make your own mail templates using Handlebars, run it through this package to generate the HTML-string which is ready to be sent with your choice of node-mailer.
Installation
npm install node-html-emails --save
Usage
const app = ; // The nhe constructorconst NHE = ; // The descriptor tells nhe what layout and partial(s) to use to generate the template// In this case the backbone of the html email will be the main layout// And the content of the email comes from the activation partial// By default nhe parses .hbs templates and registers them by their names. E.g // main.layout.hbs can be refrenced as "main", and activation.partial.hbs as activation so on..const templateDescriptors = activation: layout: 'main' content: 'activation' ; // We need to tell nhe the root of your project and it will search for *.layout.hbs and *.partial.hbs// files in it by default. But it can be configured as well.// We also need to tell nhe the directory where your translation files are heldconst nheOptions = root: path locales: locales: 'en' 'hu' directory: `/locales` // Instantiationconst nhe = templateDescriptors nheOptions; app; app;
For the example to work you will need to have a main.layout.hbs
and an activation.partial.hbs
in your project somewhere. The package will precompile these templates for you.
For example
main.layout.hbs
Example {{>content}}
activation.partial.hbs
{{ translate 'GREETING' }} {{ email }}, {{ translate 'ACTIVATION_MSG' }}
For the translation to work you'll need translation files located somewhere in your project
/locales/en.json
/locales/hu.json