# email-templates-v2

> Node.js module for rendering beautiful emails with ejs, jade, swig, hbs, or handlebars templates and email-friendly inline CSS using juice.

Latest version **2.0.3** (published 2015-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install email-templates-v2
pnpm add email-templates-v2
yarn add email-templates-v2
bun add email-templates-v2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2015-10-15 |
| First published | 2015-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10 |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | Shailendra Sharma |
| Maintainers | snow01 |
| Keywords | node-email-templates, windows, ejs, email, templates, email-templates, juice, inline, css, subject template, html template, text template, v2 |

## Links

- npm: https://www.npmjs.com/package/email-templates-v2
- Repository: https://github.com/snow01/node-email-templates-v2
- Issues: https://github.com/snow01/node-email-templates-v2/issues/new
- npm.io page: https://npm.io/package/email-templates-v2

## Dependencies (6)

- [glob](https://npm.io/package/glob.md) ^5.0.15
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [juice](https://npm.io/package/juice.md) ^1.5.1
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [bluebird](https://npm.io/package/bluebird.md) ^2.10.2
- [consolidate](https://npm.io/package/consolidate.md) ^0.13.1

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2015-10-15
- 2.0.2 — 2015-10-12

## README

# Node Email Templates

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![NPM downloads][npm-downloads]][npm-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Static Analysis][codeclimate-image]][codeclimate-url]
[![MIT License][license-image]][license-url]
[![Gitter][gitter-image]][gitter-url]
[![js-standard-style][standard-image]][standard-url]

Node.js NPM package for rendering beautiful emails with your template engine and CSS pre-processor of choice coupled with email-friendly inline CSS using [juice][juice].

> Enjoy this package? Follow [@yeliahs](https://twitter.com/yeliahs)!

## Note

This package (v2) is extended version of [email-templates](https://github.com/niftylettuce/node-email-templates). v2 adds support for templating subjects.

## Index

* [Email Templates](#email-templates)
* [Installation](#installation)
* [Quick Start](#quick-start)
* [EJS Custom Tags](#ejs-custom-tags)
* [Examples](#examples)
    * [Basic](#basic)
* [Changelog](#changelog)
* [Contributors](#contributors)
* [License](#license)


## Email Templates

For customizable, pre-built email templates, see [Email Blueprints][email-blueprints] and [Transactional Email Templates][transactional-email-templates].

#### Supported Template Engines

email-templates-v2 uses [consolidate.js][consolidate], and therefore supports a vast array of template modules. Please see [consolidate.js][consolidate] for the impressive full list.

#### Supported CSS Pre-processors

* [less][less]
* [sass][sass]
* [stylus][stylus]
* [styl][styl]


## Prerequisites

#### Important Note for Windows Users

Developing on OS X or Ubuntu/Linux is recommended, but if you only have access to a Windows machine you can do one of the following:

* Use [vagrant](http://www.vagrantup.com/) to create a linux dev environment (recommended)
* Follow the [Windows installation guide](https://github.com/brianmcd/contextify/wiki/Windows-Installation-Guide) for contextify


## Installation

Install `email-templates-v2` and the engines you wish to use by adding them to your `package.json` dependencies.

```bash
npm install --save email-templates-v2
# See https://www.npmjs.com/package/consolidate for a full list of available template engines
npm install -S [ejs|jade|nunjucks|handlebars|emblem|dust-linkedin] 
```


## Quick Start

1. Install the module for your respective project:

    ```bash
    npm install --save email-templates-v2@2
    ```

2. Install the template engine you intend to use:

    - `ejs@^2.0.0`
    - `jade@^1.0.0`
    - `nunjucks@^1.0.0`
    - `handlebars@^3.0.0`
    - `dust-linkedin@^2.0.0`
    - `less@^2.0.0`
    - `stylus@^0.51.0`
    - `styl@^0.2.0`
    - `node-sass@^3.0.0`
    
    - See https://www.npmjs.com/package/consolidate for a full list

    ```bash
    npm install --save <engine>
    ```

3. For each of your email templates (e.g. a welcome email to send to users when they register on your site), respectively name and create a folder.

    ```bash
    mkdir templates/welcome-email
    ```

4. Add the following files inside the template's folder:
    * `html.{{ext}}` (**required**) - for html format of email
    * `text.{{ext}}` (**optional**) - for text format of email
    * `style.{{ext}}`(**optional**) - styles for html format
    * `subject.{{ext}}`(**optional**) - for subject of email

    > **See [supported template engines](#supported-template-engines) for possible template engine extensions (e.g. `.ejs`, `.jade`, `.nunjucks`) to use for the value of `{{ext}}` above.**

    > You may prefix any file name with anything you like to help you identify the files more easily in your IDE.  The only requirement is that the filename contains `html.`, `text.`, `style.`, and `subject.` respectively.

5. You may use the `include` directive from [ejs][ejs] (for example, to include a common header or footer).  See the `/examples` folder for details.


## Template Engine Options

If your want to configure your template engine, just pass options.

Want to use different opening and closing tags instead of the EJS's default `<%` and `%>`?.

```javascript
new EmailTemplate(templateDir, { delimiter: '?' })
```

> You can also directly modify the template engine

```javascript
// ...
Handlebars.registerPartial('name', '{{name.first}} {{name.last}}')
Handlebars.registerHelper('capitalize', function (context) {
  return context.toUpperCase()
})
new EmailTemplate(templateDir)
// ...
```

You can also pass a `juiceOptions` object to configure the output from [juice][juice]

```javascript
new EmailTemplate(templateDir, {juiceOptions: {
  preserveMediaQueries: false,
  removeStyleTags: false
}})
```

You can check all the options in [juice's documentation](https://github.com/automattic/juice#options)

## Examples

### Basic

Render a single template (having only loaded the template once).

```javascript
var EmailTemplate = require('email-templates').EmailTemplate
var path = require('path')

var templateDir = path.join(__dirname, 'templates', 'newsletter')

var newsletter = new EmailTemplate(templateDir)
var user = {name: 'Joe', pasta: 'spaghetti'}
newsletter.render(user, function (err, results) {
  // result.html
  // result.text
})

var async = require('async')
var users = [
  {name: 'John', pasta: 'Rigatoni'},
  {name: 'Luca', pasta: 'Tortellini'}
]

async.each(users, function (user, next) {
  newsletter.render(user, function (err, results) {
    if (err) return next(err)
    // result.html
    // result.text
    // result.subject
  })
}, function (err) {
  //
})
```

Render a template for a single email or render multiple (having only loaded the template once) using Promises.

```js
var path           = require('path')
var templateDir   = path.join(__dirname, 'templates', 'pasta-dinner')
var EmailTemplate = require('email-templates').EmailTemplate

var template = new EmailTemplate(templateDir)
var users = [
  {
    email: 'pappa.pizza@spaghetti.com',
    name: {
      first: 'Pappa',
      last: 'Pizza'
    }
  },
  {
    email: 'mister.geppetto@spaghetti.com',
    name: {
      first: 'Mister',
      last: 'Geppetto'
    }
  }
]

var templates = users.map(function (user) {
  return template.render(user)
})

Promise.all(templates)
  .then(function (results) {
    console.log(results[0].html)
    console.log(results[0].text)
    console.log(results[0].subject)
    console.log(results[1].html)
    console.log(results[1].text)
    console.log(results[1].subject)
  })
```

### More

Please check the [examples directory](https://github.com/snow01/node-email-templates-v2/tree/master/examples)

## Contributors

* Nick Baugh <niftylettuce@gmail.com>
* Andrea Baccega <vekexasia@gmail.com>
* Nic Jansma <http://nicj.net>
* Jason Sims <sims.jrobert@gmail.com>
* Miguel Mota <hello@miguelmota.com>
* Jeduan Cornejo <jeduan@gmail.com>
* Shailendra Sharma <shailendra.sharma@gmail.com>

> Full list of contributors can be found on the [GitHub Contributor Graph][gh-graph]


## License

[MIT][license-url]


[ejs]: https://github.com/visionmedia/ejs
[juice]: https://github.com/Automattic/juice
[nodemailer]: https://github.com/andris9/Nodemailer
[postmark]: http://postmarkapp.com/
[postmarkjs]: https://github.com/voodootikigod/postmark.js
[nodemailer-smtp]: https://github.com/andris9/Nodemailer#well-known-services-for-smtp
[postmark-msg-format]: http://developer.postmarkapp.com/developer-build.html#message-format
[consolidate]: https://www.npmjs.com/package/consolidate
[less]: http://lesscss.org/
[sass]: http://sass-lang.com/
[stylus]: http://learnboost.github.io/stylus/
[styl]: https://github.com/visionmedia/styl
[express-cdn]: https://github.com/niftylettuce/express-cdn
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
[gh-graph]: https://github.com/snow01/node-email-templates-v2/graphs/contributors
[npm-image]: http://img.shields.io/npm/v/email-templates-v2.svg?style=flat
[npm-url]: https://npmjs.org/package/email-templates-v2
[npm-downloads]: http://img.shields.io/npm/dm/email-templates-v2.svg?style=flat
[travis-url]: http://travis-ci.org/snow01/node-email-templates-v2
[travis-image]: http://img.shields.io/travis/snow01/node-email-templates-v2.svg?style=flat
[codeclimate-image]: http://img.shields.io/codeclimate/github/snow01/node-email-templates-v2.svg?style=flat
[codeclimate-url]: https://codeclimate.com/github/snow01/node-email-templates-v2?branch=master
[coveralls-image]: https://img.shields.io/coveralls/snow01/node-email-templates-v2.svg?style=flat
[coveralls-url]: https://coveralls.io/r/snow01/node-email-templates-v2?branch=master
[gitter-url]: https://gitter.im/snow01/node-email-templates-v2
[gitter-image]: http://img.shields.io/badge/chat-online-brightgreen.svg?style=flat
[eskimo]: http://eskimo.io
[nifty-conventions]: https://github.com/niftylettuce/nifty-conventions
[email-blueprints]: https://github.com/mailchimp/Email-Blueprints
[transactional-email-templates]: https://github.com/mailgun/transactional-email-templates
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat
[standard-url]: https://github.com/feross/standard

---
_Source: https://npm.io/package/email-templates-v2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
