Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for @forwardemail, @ladjs, @cabinjs, @spamscanner, and @breejs.
Installations
npm install email-templates
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=14
Typescript Support
No
Node Version
18.16.0
NPM Version
9.5.1
Statistics
3,676 Stars
253 Commits
335 Forks
67 Watching
4 Branches
56 Contributors
Updated on 26 Nov 2024
Languages
JavaScript (95.46%)
HTML (4.02%)
Shell (0.52%)
Total Downloads
Cumulative downloads
Total Downloads
28,333,771
Last day
-6.9%
22,624
Compared to previous day
Last week
-1.8%
114,995
Compared to previous week
Last month
-11.9%
473,354
Compared to previous month
Last year
37%
6,456,026
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
18
Optional Dependencies
1
Email Templates
Create, preview (browser/iOS Simulator), and send custom email templates for Node.js. Made for Forward Email and Lad.
Need to send emails that land in the inbox instead of spam folder? Click here to learn how to send JavaScript contact forms and more with Node.js
Table of Contents
- Install
- Preview
- Usage
- Debugging
- Basic
- Attachments
- Automatic Inline CSS via Stylesheets
- Render HTML and/or Text
- Localization
- Text-Only Email (no HTML)
- Prefix Subject Lines
- Custom Text Template
- Custom Template Engine (e.g. EJS)
- Custom Default Message Options
- Custom Rendering (e.g. from a MongoDB database)
- Absolute Path to Templates
- Open Email Previews in Firefox
- Options
- Tips
- Plugins
- Breaking Changes
- Related
- Contributors
- License
Install
By default we recommend pug for your template engine, but you can use any template engine. Note that preview-email is an optional dependency and is extremely helpful for rendering development previews of your emails automatically in your browser.
npm:
1npm install email-templates preview-email pug
Preview
We've added preview-email by default to this package. This package allows you to preview emails in the browser and in the iOS Simulator.
This means that (by default) in the development environment (e.g. NODE_ENV=development
) your emails will be rendered to the tmp directory for you and automatically opened in the browser.
If you have trouble previewing emails in your browser, you can configure a preview
option which gets passed along to open's options (e.g. preview: { open: { app: 'firefox' } }
).
See the example below for Open Email Previews in Firefox.
Usage
Debugging
Environment Flag
If you run into any issues with configuration, files, templates, locals, etc, then you can use the NODE_DEBUG
environment flag:
1NODE_DEBUG=email-templates node app.js
This will output to the console all debug statements in our codebase for this package.
Inspect Message
As of v3.6.1 you can now inspect the message passed to nodemailer.sendMail
internally.
In the response object from email.send
, you have access to res.originalMessage
:
1email 2 .send({ 3 template: 'mars', 4 message: { 5 to: 'elon@spacex.com' 6 }, 7 locals: { 8 name: 'Elon' 9 } 10 }) 11 .then(res => { 12 console.log('res.originalMessage', res.originalMessage) 13 }) 14 .catch(console.error);
Basic
You can swap the
transport
option with a Nodemailer transport configuration object or transport instance. We highly recommend using Forward Email for your transport (it's the default in Lad).If you want to send emails in
development
ortest
environments, setoptions.send
totrue
.
1const Email = require('email-templates');
2
3const email = new Email({
4 message: {
5 from: 'test@example.com'
6 },
7 // uncomment below to send emails in development/test env:
8 // send: true
9 transport: {
10 jsonTransport: true
11 }
12});
13
14email
15 .send({
16 template: 'mars',
17 message: {
18 to: 'elon@spacex.com'
19 },
20 locals: {
21 name: 'Elon'
22 }
23 })
24 .then(console.log)
25 .catch(console.error);
The example above assumes you have the following directory structure:
1. 2├── app.js 3└── emails 4 └── mars 5 ├── html.pug 6 └── subject.pug
And the contents of the pug
files are:
html.pug
:
1p Hi #{name}, 2p Welcome to Mars, the red planet.
subject.pug
:
1= `Hi ${name}, welcome to Mars`
Attachments
Please reference Nodemailer's attachment documentation for further reference.
If you want to set default attachments sent with every email:
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com', 6 attachments: [ 7 { 8 filename: 'text1.txt', 9 content: 'hello world!' 10 } 11 ] 12 } 13}); 14 15email 16 .send({ 17 template: 'mars', 18 message: { 19 to: 'elon@spacex.com' 20 }, 21 locals: { 22 name: 'Elon' 23 } 24 }) 25 .then(console.log) 26 .catch(console.error);
If you want to set attachments sent individually:
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com' 6 }, 7 transport: { 8 jsonTransport: true 9 } 10}); 11 12email 13 .send({ 14 template: 'mars', 15 message: { 16 to: 'elon@spacex.com', 17 attachments: [ 18 { 19 filename: 'text1.txt', 20 content: 'hello world!' 21 } 22 ] 23 }, 24 locals: { 25 name: 'Elon' 26 } 27 }) 28 .then(console.log) 29 .catch(console.error);
Automatic Inline CSS via Stylesheets
Simply include the path or URL to the stylesheet in your template's <head>
:
1link(rel="stylesheet", href="/css/app.css", data-inline)
This will look for the file /css/app.css
in the build/
folder. Also see Optimized Pug Stylesheet Loading below.
If this asset is in another folder, then you will need to modify the default options when creating an Email
instance:
1const email = new Email({
2 // <https://github.com/Automattic/juice>
3 juice: true,
4 // Override juice global settings <https://github.com/Automattic/juice#juicecodeblocks>
5 juiceSettings: {
6 tableElements: ['TABLE']
7 },
8 juiceResources: {
9 // set this to `true` (since as of v11 it is `false` by default)
10 applyStyleTags: true, // <------------ you need to set this to `true`
11 webResources: {
12 //
13 // this is the relative directory to your CSS/image assets
14 // and its default path is `build/`:
15 //
16 // e.g. if you have the following in the `<head`> of your template:
17 // `<link rel="stylesheet" href="style.css" data-inline="data-inline">`
18 // then this assumes that the file `build/style.css` exists
19 //
20 relativeTo: path.resolve('build')
21 //
22 // but you might want to change it to something like:
23 // relativeTo: path.join(__dirname, '..', 'assets')
24 // (so that you can re-use CSS/images that are used in your web-app)
25 //
26 }
27 }
28});
Render HTML and/or Text
If you don't need this module to send your email, you can still use it to render HTML and/or text templates.
Simply use the email.render(view, locals)
method we expose (it's the same method that email.send
uses internally).
If you need to render a specific email template file (e.g. the HTML version):
1const Email = require('email-templates'); 2 3const email = new Email(); 4 5email 6 .render('mars/html', { 7 name: 'Elon' 8 }) 9 .then(console.log) 10 .catch(console.error);
The example above assumes you have the following directory structure (note that this example would only render the html.pug
file):
1. 2├── app.js 3└── emails 4 └── mars 5 ├── html.pug 6 ├── text.pug 7 └── subject.pug
The Promise for email.render
resolves with a String (the HTML or text rendered).
If you need pass juiceResources in render function, with this option you don't need create Email instance every time
1const Email = require('email-templates'); 2 3const email = new Email(); 4 5email 6 .render({ 7 path: 'mars/html', 8 juiceResources: { 9 webResources: { 10 // view folder path, it will get css from `mars/style.css` 11 relativeTo: path.resolve('mars') 12 } 13 } 14 }, { 15 name: 'Elon' 16 }) 17 .then(console.log) 18 .catch(console.error);
The example above will be useful when you have a structure like this, this will be useful when you have a separate CSS file for every template
1. 2├── app.js 3└── emails 4 └── mars 5 ├── html.pug 6 ├── text.pug 7 ├── subject.pug 8 └── style.css
The Promise for email.render
resolves with a String (the HTML or text rendered).
If you need to render all available template files for a given email template (e.g.
html.pug
,text.pug
, andsubject.pug
– you can useemail.renderAll
(this is the method thatemail.send
uses).
1const Email = require('email-templates'); 2 3const email = new Email(); 4 5email 6 .renderAll('mars', { 7 name: 'Elon' 8 }) 9 .then(console.log) 10 .catch(console.error);
If you need to render multiple, specific templates at once (but not all email templates available), then you can use
Promise.all
in combination withemail.render
:
1const Email = require('email-templates'); 2 3const email = new Email(); 4const locals = { name: 'Elon' }; 5 6Promise 7 .all([ 8 email.render('mars/html', locals), 9 email.render('mars/text', locals) 10 ]) 11 .then(([ html, text ]) => { 12 console.log('html', html); 13 console.log('text', text); 14 }) 15 .catch(console.error);
Localization
All you need to do is simply pass an i18n configuration object as config.i18n
(or an empty one as this example shows to use defaults).
Don't want to handle localization and translation yourself? Just use Lad – it's built in and uses mandarin (with automatic Google Translate support) under the hood.
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com' 6 }, 7 transport: { 8 jsonTransport: true 9 }, 10 i18n: {} // <------ HERE 11}); 12 13email 14 .send({ 15 template: 'mars', 16 message: { 17 to: 'elon@spacex.com' 18 }, 19 locals: { 20 locale: 'en', // <------ CUSTOMIZE LOCALE HERE (defaults to `i18n.defaultLocale` - `en`) 21 // is your user french? 22 // locale: 'fr', 23 name: 'Elon' 24 } 25 }) 26 .then(console.log) 27 .catch(console.error);
Then slightly modify your templates to use localization functions.
html.pug
:
1p= `${t('Hi')} ${name},` 2p= t('Welcome to Mars, the red planet.')
subject.pug
:
1p= `${t('Hi')} ${name}, ${t('welcome to Mars')}`
Note that if you use Lad, you have a built-in filter called translate
:
1p: :translate(locale) Welcome to Mars, the red planet.
Localization using Handlebars template engine
If you are using handlebars and you are using localization files with named values, you will quickly see that
there is no way to properly call the t
function in your template and specify named values.
If, for example you have this in your translation file:
1{ 2 "greetings": "Hi {{ firstname }}", 3 "welcome_message": "Welcome to Mars, the red planet." 4}
And you would like to use it in your template like this:
html.hbs
:
1<p>{{ t "greetings" firstname="Marcus" }}</p> 2<p>{{ t "welcome_message" }}</p>
This would not work because the second argument sent by handlebars to the function would be a handlebar helper options object instead of just the named values.
A possible workaround you can use is to introduce your own translation helper in your template locals:
1email 2 .send({ 3 template: 'mars', 4 message: { 5 to: 'elon@spacex.com' 6 }, 7 locals: { 8 locale: 'en', // <------ CUSTOMIZE LOCALE HERE (defaults to `i18n.defaultLocale` - `en`) 9 // is your user french? 10 // locale: 'fr', 11 name: 'Elon', 12 $t(key, options) { 13 // <------ THIS IS OUR OWN TRANSLATION HELPER 14 return options.data.root.t( 15 { phrase: key, locale: options.data.root.locale }, 16 options.hash 17 ); 18 } 19 } 20 }) 21 .then(console.log) 22 .catch(console.error);
Then slightly modify your templates to use your own translation helper functions.
html.hbs
:
1<p>{{ $t "greetings" firstname="Marcus" }}</p> 2<p>{{ $t "welcome_message" }}</p>
Text-Only Email (no HTML)
If you wish to have only a text-based version of your email you can simply pass the option textOnly: true
.
Regardless if you use the htmlToText
option or not (see next example), it will still render only a text-based version.
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com' 6 }, 7 transport: { 8 jsonTransport: true 9 }, 10 textOnly: true // <----- HERE 11}); 12 13email 14 .send({ 15 template: 'mars', 16 message: { 17 to: 'elon@spacex.com' 18 }, 19 locals: { 20 name: 'Elon' 21 } 22 }) 23 .then(console.log) 24 .catch(console.error);
Prefix Subject Lines
You can pass an option to prefix subject lines with a string, which is super useful for deciphering development / staging / production environment emails.
For example, you could make it so on non-production environments the email is prefixed with a [DEVELOPMENT] Some Subject Line Here
.
You could do this manually by passing a message.subject
property, however if you are storing your subject lines in templates (e.g. subject.ejs
or subject.pug
) then it's not as easy.
Simply use the subjectPrefix
option and set it to whatever you wish (note you will need to append a trailing space if you wish to have a space after the prefix; see example below):
1const Email = require('email-templates'); 2 3const env = process.env.NODE_ENV || 'development'; 4 5const email = new Email({ 6 message: { 7 from: 'test@example.com' 8 }, 9 transport: { 10 jsonTransport: true 11 }, 12 subjectPrefix: env === 'production' ? false : `[${env.toUpperCase()}] `; // <--- HERE 13});
Custom Text Template
By default we use
html-to-text
to generate a plaintext version and attach it asmessage.text
.
If you'd like to customize the text body, you can pass message.text
or create a text
template file just like you normally would for html
and subject
.
You may also set config.htmlToText: false
to force the usage of the text
template file.
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com' 6 }, 7 transport: { 8 jsonTransport: true 9 }, 10 htmlToText: false // <----- HERE 11}); 12 13email 14 .send({ 15 template: 'mars', 16 message: { 17 to: 'elon@spacex.com' 18 }, 19 locals: { 20 name: 'Elon' 21 } 22 }) 23 .then(console.log) 24 .catch(console.error);
text.pug
:
1| Hi #{name}, 2| Welcome to Mars, the red planet.
Custom Template Engine (e.g. EJS)
-
Install your desired template engine (e.g. EJS)
npm:
1npm install ejs
-
Set the extension in options and send an email
1const Email = require('email-templates'); 2 3const email = new Email({ 4 message: { 5 from: 'test@example.com' 6 }, 7 transport: { 8 jsonTransport: true 9 }, 10 views: { 11 options: { 12 extension: 'ejs' // <---- HERE 13 } 14 } 15});
Custom Default Message Options
You can configure your Email instance to have default message options, such as a default "From", an unsubscribe header, etc.
For a list of all available message options and fields see the Nodemailer message reference.
Here's an example showing how to set a default custom header and a list unsubscribe header:
1const Email = require('email-templates');
2
3const email = new Email({
4 message: {
5 from: 'test@example.com',
6 headers: {
7 'X-Some-Custom-Thing': 'Some-Value'
8 },
9 list: {
10 unsubscribe: 'https://example.com/unsubscribe'
11 }
12 },
13 transport: {
14 jsonTransport: true
15 }
16});
Custom Rendering (e.g. from a MongoDB database)
You can pass a custom config.render
function which accepts two arguments view
and locals
and must return a Promise
.
Note that if you specify a custom config.render
, you should have it use email.juiceResources
before returning the final HTML. The example below shows how to do this.
If you wanted to read a stored EJS template from MongoDB, you could do something like:
1const ejs = require('ejs'); 2 3const email = new Email({ 4 // ... 5 render: (view, locals) => { 6 return new Promise((resolve, reject) => { 7 // this example assumes that `template` returned 8 // is an ejs-based template string 9 // view = `${template}/html` or `${template}/subject` or `${template}/text` 10 db.templates.findOne({ name: view }, (err, template) => { 11 if (err) return reject(err); 12 if (!template) return reject(new Error('Template not found')); 13 let html = ejs.render(template, locals); 14 html = await email.juiceResources(html); 15 resolve(html); 16 }); 17 }); 18 } 19});
Absolute Path to Templates
As of v5.0.1+ we now support passing absolute paths to templates for rendering (per discussion in #320.
For both email.send
and email.render
, the template
option passed can be a relative path or absolute:
Relative example:
1email 2 .send({ 3 template: 'mars', 4 message: { 5 to: 'elon@spacex.com' 6 }, 7 locals: { 8 name: 'Elon' 9 } 10 }) 11 .then(console.log) 12 .catch(console.error);
Absolute example:
1const path = require('path'); 2 3// ... 4 5email 6 .send({ 7 template: path.join(__dirname, 'some', 'folder', 'mars') 8 message: { 9 to: 'elon@spacex.com' 10 }, 11 locals: { 12 name: 'Elon' 13 } 14 }) 15 .then(console.log) 16 .catch(console.error);
Open Email Previews in Firefox
The preview
option can be a custom Object of options to pass along to open's options.
Firefox example:
1const email = new Email({ 2 // ... 3 preview: { 4 open: { 5 app: 'firefox', 6 wait: false 7 } 8 } 9});
Options
For a list of all available options and defaults view the configuration object, or reference the list below:
views
(Object)root
(String) - defaults to the current working directory's "emails" folder viapath.resolve('emails')
options
(Object)extension
(String) - defaults to'pug'
, and is the default file extension for templatesmap
(Object) - a template file extension mapping, defaults to{ hbs: 'handlebars', njk: 'nunjucks' }
(this is useful if you use different file extension naming conventions)engineSource
(Object) - the default template engine source, defaults to @ladjs/consolidate
locals
(Object) - locals to pass to templates for renderingcache
(Boolean) - defaults tofalse
fordevelopment
andtest
environments, andtrue
for all others (viaprocess.env.NODE_ENV
), whether or not to cache templatespretty
(Boolean) - defaults totrue
, but is automatically set tofalse
for subject templates and text-based emails
message
(Object) - default Nodemailer message object for messages to inherit (defaults to an empty object{}
)send
(Boolean) - whether or not to send emails, defaults tofalse
fordevelopment
andtest
environments, andtrue
for all others (viaprocess.env.NODE_ENV
) (NOTE: IF YOU ARE NOT USINGNODE_ENV
YOU WILL NEED TO MANUALLY SET THIS TOtrue
)preview
(Boolean or Object) - whether or not to preview emails using preview-email, defaults tofalse
unless the environment isdevelopment
(viaprocess.env.NODE_ENV
) – if you wish to disable the iOS Simulator then pass{ openSimulator: false }
i18n
(Boolean or Object) - translation support for email templates, this accepts an I18N configuration object (defaults tofalse
, which means it is disabled) which is passed along to @ladjs/i18n – see Localization example for more insightrender
(Function) - defaults to a stable function that accepts two argument,view
(String) andlocals
(Object) - you should not need to set this unless you have a need for custom rendering (see Custom Rendering (e.g. from a MongoDB database))customRender
(Boolean) - defaults tofalse
, unless you pass your ownrender
function, and in that case it will be automatically set totrue
textOnly
(Boolean) - whether or not to force text-only rendering of a template and disregard the template folder (defaults tofalse
)htmlToText
(Object) - configuration object for html-to-textignoreImage
(Boolean) - defaults totrue
subjectPrefix
(Boolean or String) - defaults tofalse
, but if set to a string it will use that string as a prefix for your emails' subjectsjuice
(Boolean) - whether or not to use juice when rendering templates (defaults totrue
) (note that if you have a custom rendering function you will need to implement juice in it yourself)juiceResources
(Object) - options to pass tojuice.juiceResources
method (only used ifjuice
option is set totrue
, see juice's API for more informationapplyStyleTags
(Boolean) - defaults tofalse
(as of v11, since modern browsers now support<style>
tag in<head>
section)removeStyleTags
(Boolean) - defaults tofalse
(as of v11, since modern browsers now support<style>
tag in<head>
section)webResources
(Object) - an options object that will be passed to web-resource-inlinerrelativeTo
(String) - defaults to the current working directory's "build" folder viapath.resolve('build')
(NOTE: YOU SHOULD MODIFY THIS PATH TO WHERE YOUR BUILD/ASSETS FOLDER IS)images
(Boolean or Number) - defaults tofalse
, and is whether or not to inline images unless they have an exclusion attribute (see web-resource-inliner for more insight), if it is set to a Number then that is used as the KB threshold
transport
(Object) - a transport configuration object or a Nodemailer transport instance created vianodemailer.createTransport
, defaults to an empty object{}
, see Nodemailer transports documentation for more insightgetPath
(Function) - a function that returns the path to a template file, defaults tofunction (type, template) { return path.join(template, type); }
, and accepts three argumentstype
,template
, andlocals
Tips
Purge unused CSS
See the gulpfile.js
file and email
directory in the Forward Email codebase for insight as to how to use purge-css
across your email templates.
Optimized Pug Stylesheet Loading
Note that if you're using pug, you can use the following pattern to optimize compile time for rendering in your email layout.
1doctype html 2html 3 head 4- link(rel='stylesheet', href='style.css', data-inline) 5+ style 6+ include style.css 7 body 8 p Hello
This makes use of pug includes – which saves compilation time for rendering (since web-resource-inliner will not have to fetch the external stylesheet).
Plugins
You can use any nodemailer plugin. Simply pass an existing transport instance as config.transport
.
You should add the nodemailer-base64-to-s3 plugin to convert base64 inline images to actual images stored on Amazon S3 and Cloudfront.
When doing so (as of v4.0.2+), you will need to adjust your email-templates
configuration to pass images: true
as such:
1const email = new Email({ 2 // ... 3 juiceResources: { 4 webResources: { 5 relativeTo: path.resolve('build'), 6 images: true // <--- set this as `true` 7 } 8 } 9});
Breaking Changes
See the Releases page for an up to date changelog.
v12.0.0
The preview-email
dependency is now an optional dependency. You will need to npm install preview-email
or set preview: false
, otherwise an error will be thrown in non-production environments and console.error
in production environments if preview
option is a truthy value. The default value for preview
is preview: process.NODE_ENV === 'development'
.
v11.0.0
This package no longer inlines stylesheets by default and preserves <style>
tags in the <head>
(see Options).
A majority of email clients support <style>
tags in the <head>
section – and inlining CSS is no longer necessary.
See 1, 2, and 3 as references.
v10.0.0
This package now requires Node v14+.
v9.0.0
This package now requires Node v10.x+ due to web-resource-inliner dependency.
v8.0.0
We upgraded html-to-text to v6. As a result, automatically generated text versions of your emails will look slightly different, as per the example below:
1+Hi, 2+ 3+email-templates rocks! 4+ 5+Cheers, 6+The team 7-Hi,email-templates rocks! 8-Cheers,The team
v7.0.0
We upgraded preview-email
to v2.0.0
, which supports stream attachments, and additionally the view rendering is slightly different (we simply iterate over header lines and format them in a <pre><code>
block). A major version bump was done due to the significant visual change in the preview rendering of emails.
v6.0.0
-
Performance should be significantly improved as the rendering of subject, html, and text parts now occurs asynchronously in parallel (previously it was in series and had blocking lookup calls).
-
We removed bluebird and replaced it with a lightweight alternative pify (since all we were using was the
Promise.promisify
method frombluebird
as well). -
This package now only supports Node v8.x+ (due to preview-email's open dependency requiring it).
-
Configuration for the
preview
option has slightly changed, which now allows you to specify a custom template and stylesheets for preview rendering.If you were using a custom
preview
option before, you will need to change it slightly:1const email = new Email({ 2 // ... 3 preview: { 4+ open: { 5+ app: 'firefox', 6+ wait: false 7+ } 8- app: 'firefox', 9- wait: false 10 } 11});
v5.0.0
In version 4.x+, we changed the order of defaults being set. See #313 for more information. This allows you to override message options such as from
(even if you have a global default from
set).
v4.0.0
See v5.0.0 above
v3.0.0
If you are upgrading from v2 or prior to v3, please note that the following breaking API changes occurred:
-
You need to have Node v6.4.0+, we recommend using nvm to manage your Node versions.
-
Instead of calling
const newsletter = new EmailTemplate(...args)
, you now callconst email = new Email(options)
.- The arguments you pass to the constructor have changed as well.
- Previously you'd pass
new EmailTemplate(templateDir, options)
. Now you will need to pass simply one object with a configuration as an argument to the constructor. - If your
templateDir
path is the "emails" folder in the root of your project (basically./emails
folder) then you do not need to pass it at all since it is the default per the configuration object. - The previous value for
templateDir
can be used as such:
1-const newsletter = new EmailTemplate(templateDir); 2+const email = new Email({ 3+ views: { root: templateDir } 4+});
- Note that if you are inlining CSS, you should also make sure that the option for
juiceResources.webResources.relativeTo
is accurate.
-
Instead of calling
newsletter.render(locals, callback)
you now callemail.render(template, locals)
. The return value ofemail.render
when invoked is aPromise
and does not accept a callback function.NOTE:
email-templates
v3 now has anemail.send
method (see basic usage example) which usesnodemailer
; you should now useemail.send
instead ofemail.render
!1-newsletter.render({}, (err, result) => { 2- if (err) return console.error(err); 3- console.log(result); 4-}); 5+email.render(template, {}).then(console.log).catch(console.error);
-
Localized template directories are no longer supported. We now support i18n translations out of the box. See Localization for more info.
-
A new method
email.send
has been added. This allows you to create a Nodemailer transport and send an email template all at once (it callsemail.render
internally). See the Basic usage documentation above for an example. -
There are new options
options.send
andoptions.preview
. Both are Boolean values and configured automatically based off the environment. Take a look at the configuration object. Note that you can optionally pass an Object topreview
option, which gets passed along to open's options. -
If you wish to send emails in development or test environment (disabled by default), set
options.send
totrue
.
Related
- forward-email - Free, encrypted, and open-source email forwarding service for custom domains
- custom-fonts-in-emails - render any font in emails as an image w/retina support (no more Photoshop or Sketch exports)
- font-awesome-assets - render any Font Awesome icon as an image in an email w/retina support (no more Photoshop or Sketch exports!)
- lad - Scaffold a Koa webapp and API framework for Node.js
- lass - Scaffold a modern boilerplate for Node.js
- cabin - Logging and analytics solution for Node.js, Lad, Koa, and Express
Contributors
Name | Website |
---|---|
Nick Baugh | http://niftylettuce.com |
License
MIT © Nick Baugh
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/forwardemail/.github/SECURITY.md:1
- Info: Found linked content: github.com/forwardemail/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/forwardemail/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/forwardemail/.github/SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/forwardemail/email-templates/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/forwardemail/email-templates/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:25
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
4.1
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More