npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mailor

v0.4.9

Published

Low-cost mailing authoring

Downloads

61

Readme

Mailor

This module glues Maildev and MJML with some Pug and Mustache to enable an easier development workflow for mailings on NodeJS.

NPM version Build status Coverage Status Known Vulnerabilities

Get it globally or within your project:

$ npm i -g mailor # or `npm i mailor --save-dev`

Use mailor init to create a templates/ 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 the class attribute by default while mj-* requires css-class instead.

Build or watch for changes, e.g.

$ mailor watch templates -d generated --no-open

Once built, try sending it through the local SMTP, e.g.

$ mailor send generated/test1.html

Open http://localhost:1081 and see how it looks!

Templating support

By default, e-mail templates are built using .pug files.

However, you can use Mustache, Handlebars or Liquid templates for further rendering, e.g.

mjml
  Body: Section
    Column: Text
      h1 Hello, {{firstName}}!

The example above generates the required HTML for the MJML post-processing, this lefts the {{...}} mustaches without changes.

Now, when you call sendMail(...) you can pass { data: { firstName: 'John' } } and the mustache will be rendered as expected.

Change the post-renderer with Mustache.setEngine('mustache' | 'handlebars' | 'liquidjs') in your code.

LESS.js support

You can pre-process and embed the resulting stylesheet through LESS, e.g.

mjml
  Head
    Style(src='_your_stylesheets.less')

The src attribute used here is non MJML standard, so mj-style won't work the same way — also, if your file is not .less then 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 _/header

Live preview

The included live-preview app allows you to watch your generated templates, input variables are extracted directly from your templates so you can test with real data.

You can leverage on the jsonfile option to setup default variables too — notice that on Mustache some values can be objects, arrays or functions.

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({
  attachments: [{
    filename: `receipt-${receipt.id}.xml`,
    content: receipt.data,
  }],
  headers: {
    'x-mailgun-variables': JSON.stringify({ t: 42 }),
  },
  callback(options) {
    options.headers['x-mailgun-tag'] = 'test';
  },
  template: 'path/to/tpl.html',
  subject: 'Test',
  email: '[email protected]',
  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"