GithubHelp home page GithubHelp logo

mustache-mailer's Introduction

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:
  • foo.text.hbs, for text email templates.
  • foo.meta.hbs, meta information in JSON format, e.g., subject.
  • foo.html.hbs, for html email templates.
  1. instantiate MustacheMailer with:
  • transport: the transport module you wish to use, e.g., SES.
  • templateDir: the path to the template directory.
var mm = new MustacheMailer({
  transport: require('nodemailer-ses-transport')({
      accessKeyId: 'AWSACCESSKEY',
      secretAccessKey: 'AWS/Secret/key'
  }),
  templateDir: './mail-templates'
});
  1. use the MessageMailer instance to grab a template:
  • if it sees an html template and a text template, both will be sent.
  • any variable passed to sendMail are sent to nodemailer, and to the mustache templates.
var msg = mm.message('confirmation', function(err, msg) {
  msg.sendMail({
    to: '[email protected]',
    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:

var mm = new MustacheMailer({
  transport: mock,
  templateDir: path.resolve(__dirname, './fixtures'),
  // a fake token facilitator.
  tokenFacilitator: {
    generate: function(data, cb) {
      setTimeout(function() {
        data.email.should.eql('[email protected]');
        data.name.should.eql('Zeke');
        return cb(null, parseInt(Math.random() * 256));
      }, 20);
    }
  }
});

In the template

http://example.com/{{{tokenHelper name=name email=email}}}
  • the arguments will be stored as key, value pairs in data.

mustache-mailer's People

Contributors

aearly avatar bcoe avatar ceejbot avatar nexdrew avatar rockbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

odame isabella232

mustache-mailer's Issues

changelog

a changelog would be super cool because this dep seems to be causing a lot of failing tests on npm-website and it's hard to tell what changed in 4.0.0. lemme know if you'd like help on it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.