npm/mustache-mailer

Name: mustache-mailer

Owner: npm

Description: send emails using nodemailer and mustache templates

Created: 2015-02-14 02:17:46.0

Updated: 2018-01-22 18:45:40.0

Pushed: 2018-01-12 21:36:17.0

Homepage: null

Size: 88

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Mustache-Mailer

Build Status Coverage Status

A mustache-template-backed mailer. Built with handlebars, and nodemailer, inspired by ActionMailer.

Usage

  1. create a templates directory with the following naming convention:

  2. foo.text.hbs, for text email templates.

  3. foo.meta.hbs, meta information in JSON format, e.g., subject.

  4. foo.html.hbs, for html email templates.

  5. instantiate MustacheMailer with:

  6. transport: the transport module you wish to use, e.g., SES.

  7. templateDir: the path to the template directory.

mm = new MustacheMailer({
ansport: require('nodemailer-ses-transport')({
  accessKeyId: 'AWSACCESSKEY',
  secretAccessKey: 'AWS/Secret/key'
,
mplateDir: './mail-templates'

  1. use the MessageMailer instance to grab a template:
  2. if it sees an html template and a text template, both will be sent.
  3. any variable passed to sendMail are sent to nodemailer, and to the mustache templates.
msg = mm.message('confirmation', function(err, msg) {
g.sendMail({
to: 'bencoe@gmail.com',
name: 'Ben',
id: 'adfasdfadsfasdf'
;

tokenFacilitator Plugin

It often arises that you'd like to toss a token inside an email, e.g., click this confirmation link to change your password.

For generating these tokens, MustacheMailer allows you to install a tokenFacilitator plugin:

When instantiating MustacheMailer:
mm = new MustacheMailer({
ansport: mock,
mplateDir: path.resolve(__dirname, './fixtures'),
 a fake token facilitator.
kenFacilitator: {
generate: function(data, cb) {
  setTimeout(function() {
    data.email.should.eql('zeke@example.com');
    data.name.should.eql('Zeke');
    return cb(null, parseInt(Math.random() * 256));
  }, 20);
}


In the template

://example.com/{{{tokenHelper name=name email=email}}}

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.