express-email

1.1.1 • Public • Published

Express email

Email solution in node.js.
Render by node-email-templates
Preview by express.js
Send by nodemailler

Usage

var billing_email = require('express-email')(__dirname + '/email/billing');

// preview
if (app.get('env') === 'development') {
  var locals = {activation_code: '000000-0000-00000000-000000-00000000'};
  app.get('/_mail/billing', billing_email.preview(locals));
}

// render
app.get('/sendBilling', function(req, res, next) {
  // ...
  var locals = {activation_code: ...};
  billing_email.render(locals, function(err, result) {
    // result.html
    // result.text
    // result.attachments
    transporter.sendEmail({
      from: ...,
      to: ...,
      subject: ...,
      html: result.html,
      text: result.text,
      attachments: result.attachments
    });
  });
});

API

  • ExpressEmail(mail_dir, [res_dir]) -> EmailEngine

    mail_dir: see [node-email-templates]
    res_dir: for seaching cid, default: mail_dir

  • EmailEngine#preview(locals) -> Express handler

    example: app.get('/_email', engine.preview(locals)); locals: for render template

    In brower:
    get /_email -> email preview

  • EmailEngine#render(locals, callback)

    locals: for render template
    callback: function(err, result)
    result.html: html result
    result.text: text result
    result.attachments: attachments for cid

Notice: you can reference cids in your html template, Express email will known it, and find them in res_dir, and generate result.attachments

Change Logs

  • 1.1.0: Preview html and text in one url

Readme

Keywords

none

Package Sidebar

Install

npm i express-email

Weekly Downloads

5

Version

1.1.1

License

BSD-3-Clause

Last publish

Collaborators

  • pjincz