Preview and send email in express.js

Usage no npm install needed!

<script type="module">
  import expressEmail from '';


Express email

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


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
      from: ...,
      to: ...,
      subject: ...,
      html: result.html,
      text: result.text,
      attachments: result.attachments


  • 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