# Nodemailer MJML i18next Compiler — Full Context > Nodemailer compile plugin that renders MJML templates with Handlebars and i18next translations to produce responsive HTML emails from MJML. This full-context file embeds the key local documentation and source to help LLMs answer questions without fetching external links. See also `llms.txt` for a concise index and external references. ## File: README.md ```markdown **Nodemailer MJML i18next Compiler** [![Docs](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://xjodoin.github.io/nodemailer-mjml-i18next-compiler/) [![npm](https://img.shields.io/npm/v/nodemailer-mjml-i18next-compiler)](https://www.npmjs.com/package/nodemailer-mjml-i18next-compiler) [![npm downloads](https://img.shields.io/npm/dm/nodemailer-mjml-i18next-compiler)](https://www.npmjs.com/package/nodemailer-mjml-i18next-compiler) - **Purpose:** Nodemailer compile plugin that renders MJML templates with Handlebars and i18next translations. - **Why:** Write responsive emails in MJML, keep copy in i18next JSON files, and inject dynamic data via Handlebars. **Install** - `npm i nodemailer mjml i18next i18next-fs-backend handlebars` - Add this plugin as a dependency of your project (copy this folder or publish and `npm i nodemailer-mjml-i18next-compiler`). - Install from npm: https://www.npmjs.com/package/nodemailer-mjml-i18next-compiler **Usage** ```js const nodemailer = require('nodemailer'); const { mjmlI18nextCompiler } = require('nodemailer-mjml-i18next-compiler'); const transporter = nodemailer.createTransport({ /* SMTP config */ }); transporter.use('compile', mjmlI18nextCompiler({ templatesDir: path.join(__dirname, 'templates'), partialsDir: path.join(__dirname, 'templates', 'partials'), localesDir: path.join(__dirname, 'locales'), defaultLocale: 'en', namespaces: ['common', 'emails'], defaultNamespace: 'common', mjmlOptions: { validationLevel: 'soft' }, strict: false, // set true to error on MJML warnings })); await transporter.sendMail({ from: 'no-reply@example.com', to: 'user@example.com', template: 'welcome', // resolves templates/welcome.mjml.hbs locale: 'en', context: { name: 'Taylor' }, // handlebars + i18next interpolation data // subject: 'Custom subject', // subjectKey: 'emails:welcome.subject', }); ``` **Templates** - Place templates under `templatesDir`. The resolver tries in order: - `.mjml.hbs` - `.hbs.mjml` - `.mjml` - `.hbs` Inside templates, you can use Handlebars and the `t` helper for translations: ```mjml {{t "emails:welcome.title" name=name}} {{t "common:greeting" name=name}} ``` **i18next** - By default, the plugin initializes its own i18next instance with `i18next-fs-backend` and loads from `locales//.json`. - Provide your own initialized instance via `i18next` option to integrate with an existing i18next setup. - In templates, `{{t "key"}}` and `{{__ "key"}}` are available. Locale is taken from `mail.data.locale`. **Options** - `templatesDir`: Absolute path to MJML/Handlebars templates. Required. - `partialsDir`: Optional absolute path to Handlebars partials. - `localesDir`: Absolute path to i18next locales folder. Default: `locales`. - `defaultLocale`: Fallback language. Default: `en`. - `namespaces`: i18next namespaces to use. Default: `["common"]`. - `defaultNamespace`: Default i18next namespace. Default: `"common"`. - `preload`: Locales to preload. Default: `[defaultLocale]`. - `mjmlOptions`: Options passed to `mjml()`. - `autoSubject`: If no subject and translation exists at `emails.