Skip to content
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
Branch: master
Clone or download
Latest commit 7373139 Jan 10, 2019

README.md

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' } ]
};

// note that `attachments` will not be parsed unless you use
// `previewEmail` with the results of `transport.sendMail`
// e.g. `previewEmail(JSON.parse(res.message));` where `res`
// is `const res = await transport.sendMail(message);`
previewEmail(message).then(console.log).catch(console.error);

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

Options

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

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

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.

The options argument is an Object which defaults to { wait: false }. This object is passed along to opn's options.

Contributors

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

License

MIT © Nick Baugh

You can’t perform that action at this time.