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`Use
mailor initto create atemplates/directory with an example.pug ready play with!
Now, you can start creating templates using pure .pug files:
templates/test1.pug
mjml
Body: Section
Column: Text
h1 It works!Shortcuts for
mj-*tags are provided as<Column />to produce<mj-column />respectively — those tags supports theclassattribute by default whilemj-*requirescss-classinstead.
Build or watch for changes, e.g.
$ mailor watch templates -d generated --no-openOnce built, try sending it through the local SMTP, e.g.
$ mailor send generated/test1.htmlOpen http://localhost:1081 and see how it looks!
LESS.js support
You can pre-process and embed the resulting stylesheet through LESS, e.g.
mjml
Head
Style(src='_your_stylesheets.less')The
srcattribute used here is non MJML standard, somj-stylewon't work the same way — also, if your file is not.lessthen it'll be embedded without changes.
Including files
By default all files or directories starting with _ are ignored by the compiler, e.g.
mjml
Head
include _/headerAPI
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 -d generated username="John Doe" token="x-f4c8"