Skip to content

Nodemailer MJML i18next Compiler

npm npm downloads

A Nodemailer compile plugin that renders MJML templates with Handlebars and i18next translations.

Features

  • MJML + Handlebars: write responsive email templates with dynamic data.
  • i18next: store copy in JSON locales; use {{t "key"}} in templates.
  • Partials: organize templates via Handlebars partials.
  • Subject translation: use a namespaced key or derive from template name.

Install

npm i nodemailer mjml i18next i18next-fs-backend handlebars
npm i nodemailer-mjml-i18next-compiler

Then install this plugin (from npm when published), or copy the package into your repo.

Quick Start

import path from 'node:path';
import nodemailer from 'nodemailer';
import { mjmlI18nextCompiler } from 'nodemailer-mjml-i18next-compiler';

const transporter = nodemailer.createTransport({ jsonTransport: true });

transporter.use('compile', mjmlI18nextCompiler({
  templatesDir: path.join(process.cwd(), 'templates'),
  partialsDir: path.join(process.cwd(), 'templates', 'partials'),
  localesDir: path.join(process.cwd(), 'locales'),
  defaultLocale: 'en',
  namespaces: ['common', 'emails'],
  defaultNamespace: 'common',
  mjmlOptions: { validationLevel: 'soft' },
}));

const info = await transporter.sendMail({
  from: 'no-reply@example.com',
  to: 'user@example.com',
  template: 'welcome',
  locale: 'en',
  context: { name: 'Taylor', app: 'MyApp' },
});

console.log(info.message.toString());

See Usage for templates, helpers, and i18next tips.

LLM Context

  • llms.txt: concise, curated pointers for LLMs — view
  • llms-full.txt: embedded docs and source excerpts — view