Package Exports
- mailor
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mailor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Mailor
This module glues Maildev and MJML with some Pug and Mustache to enable an easier development workflow for mailings on NodeJS.
Get it globally or within your project:
$ npm i -g mailor # or `npm i mailor --save-dev`
Now, you can start creating templates using pure .pug
files:
templates/test1.pug
mjml
mj-body: mj-section
mj-column: mj-text
h1 It works!
Build or watch for changes, e.g.
$ mailor watch templates -o generated --no-open
Once built, try sending it through the local SMTP, e.g.
$ mailor send generated/test1.html
Open http://localhost:1080 and see how it looks!
API
By default maildev
is enabled when watch mode is used.
The send
command uses nodemailer
for sending messages through.
You can, however, reuse this module too:
const nodemailer = require('nodemailer');
const mailer = require('mailor').getMailer({
transport: nodemailer.createTransport(...),
internalErrors: [],
});
mailer.sendMail({
template: 'path/to/tpl.html',
subject: 'Test',
email: 'test@example.com',
data: { ... },
});
You MUST provide a working transport
and optionally a list of internal error messages to be aware of, if any matches an exception will be thrown.
Using input
Local variables are given as data
and they're rendered by Mustache to build the message to be sent.
Locals for pug-templates MUST be provided as values during mailor
invocation, e.g.
$ mailor build templates -o generated username="John Doe" token="x-f4c8"