Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@greendeck/preview-email
Advanced tools
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
npm:
npm install preview-email
yarn:
yarn add preview-email
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 options.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);
Using the options.template
object, you can define your own template for rendering (e.g. get inspiration from template.pug and write your own!):
const path = require('path');
// ...
previewEmail(message, { template: path.join(__dirname, 'my-custom-preview-template.pug') })
.then(console.log)
.catch(console.error);
Thanks to the debug package, you can easily debug output from preview-email
:
DEBUG=preview-email node app.js
message
(Object) - a Nodemailer message configuration objectoptions
(Object) - an object with the following two properties:
id
(String) - a unique ID for the file name created for the preview in dir
(defaults to uuid.v4()
from uuid)dir
(String) - a path to a directory for saving the generated email previews (defaults to os.tmpdir()
, see os docs for more insight)open
(Object or Boolean) - an options object that is passed to open (defaults to { wait: false }
) - if set to false
then it will not open the email automatically in the browser using open, and if set to true
then it will default to { wait: false }
template
(String) - a file path to a pug
template file (defaults to preview-email's template.pug by default) - this is where you can pass a custom template for rendering email previews, e.g. your own stylesheeturlTransform
(Function (path) => url) - a function to build preview url from file path (defaults to (path) => 'file://[file path]'
) - this is where you can customize the opened path to handle WSL to Windows transformation or build a http url if dir
is served.Name | Website |
---|---|
Nick Baugh | http://niftylettuce.com/ |
FAQs
Automatically opens your browser to preview Node.js email messages sent with Nodemailer. Made for Lad!
We found that @greendeck/preview-email demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.