mailer-q-ejs
v3.0.0
Published
EJS template renderer for the MailerQ mailer queue
Maintainers
Readme
Mailer-Q-EJS
An EJS template renderer for MailerQ.
It lets MailerQ render email bodies from .ejs template files instead of inline HTML.
A MailerQ renderer is any function (templateFileName, locals) => htmlString. This package
provides one backed by EJS.
Installation
npm install mailer-q-ejs --saveUsage
Call the module with the directory that holds your email templates, then pass the result as
MailerQ's renderer option:
const path = require("path");
const MailerQ = require("mailer-q").default;
// or, with ESM / TypeScript: import MailerQ from "mailer-q";
const MailerQEjs = require("mailer-q-ejs");
const options = {
// ...other MailerQ options
renderer: MailerQEjs(path.join(__dirname, "./email_templates")),
};
module.exports = MailerQ(options);Then reference a template by file name when building a message, passing template variables
through locals:
MailerQ.contents({
to: "[email protected]",
subject: "Welcome!",
templateFileName: "welcome.ejs",
locals: { name: "Ada" },
}).deliverNow();email_templates/welcome.ejs:
<h1>Welcome, <%= name %>!</h1>Development
This package is written in TypeScript and compiled to dist/ with tsc.
npm run build # compile TypeScript to dist/
npm test # run the Vitest suite
npm run lint # eslintChangelog
See CHANGELOG.md for the notable changes in each release.
