JSPM

  • Created
  • Published
  • Downloads 322999
  • Score
    100M100P100Q176969F
  • License MIT

Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!

Package Exports

  • preview-email

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (preview-email) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

preview-email

build status code coverage code style styled with prettier made with lass license

Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!

VIEW THE DEMO

Table of Contents

Install

npm:

npm install preview-email

yarn:

yarn add preview-email

Usage

NOTE: You should probably just use email-templates directly instead of using this package.

The function previewEmail returns a Promise which resolves with a URL. We automatically open the browser to this URL unless you specify the third argument open as false (see Options for more info).

const previewEmail = require('preview-email');
const nodemailer = require('nodemailer');

const transport = nodemailer.createTransport({
  jsonTransport: true
});

// <https://nodemailer.com/message/>
const message = {
  from: 'niftylettuce+from@gmail.com',
  to: 'niftylettuce+to@gmail.com',
  subject: 'Hello world',
  html: '<p>Hello world</p>',
  text: 'Hello world',
  attachments: [ { filename: 'hello-world.txt', content: 'Hello world' } ]
};

previewEmail(message).then(console.log).catch(console.error);

transport.sendMail(message).then(console.log).catch(console.error);

Options

Note that you can also pass two additional arguments to previewEmail function.

These arguments are id and open (e.g. previewEmail(message, id, open)).

By default we automatically set an id using uuid.v4() (see uuid for more info).

Also, open is set to true by default - this means that we automatically open the browser for you.

Contributors

Name Website
Nick Baugh http://niftylettuce.com/

License

MIT © Nick Baugh