%PDF- %PDF-
Direktori : /home/opti/workflow/node_modules/preview-email/ |
Current File : /home/opti/workflow/node_modules/preview-email/README.md |
# preview-email [](https://travis-ci.org/niftylettuce/preview-email) [](https://codecov.io/gh/niftylettuce/preview-email) [](https://github.com/sindresorhus/xo) [](https://github.com/prettier/prettier) [](https://lass.js.org) [](<>) > Automatically opens your browser to preview [Node.js][node] email messages sent with [Nodemailer][]. Made for [Lad][]! **[VIEW THE DEMO](demo.png)** ## Table of Contents * [Install](#install) * [Usage](#usage) * [Options](#options) * [Contributors](#contributors) * [License](#license) ## Install [npm][]: ```sh npm install preview-email ``` [yarn][]: ```sh 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](#options) for more info). ```js 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][opn-options]. ## Contributors | Name | Website | | -------------- | -------------------------- | | **Nick Baugh** | <http://niftylettuce.com/> | ## License [MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/) ## [npm]: https://www.npmjs.com/ [yarn]: https://yarnpkg.com/ [email-templates]: https://github.com/niftylettuce/email-templates [node]: https://nodejs.org/ [nodemailer]: https://nodemailer.com [uuid]: https://github.com/kelektiv/node-uuid [lad]: https://lad.js.org [opn]: https://github.com/sindresorhus/opn [opn-options]: https://github.com/sindresorhus/opn#options