# email-builder-core-min

> Minimal options email builder core. Provides useful methods to inline css and send email tests

Latest version **0.0.2** (published 2019-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install email-builder-core-min
pnpm add email-builder-core-min
yarn add email-builder-core-min
bun add email-builder-core-min
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-03-19 |
| First published | 2019-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 31.4 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | zpaav |
| Keywords | email, inline, css, html, test |

## Links

- npm: https://www.npmjs.com/package/email-builder-core-min
- Repository: https://bitbucket.org/Zpaav/email-builder-core-min
- npm.io page: https://npm.io/package/email-builder-core-min

## Dependencies (13)

- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [juice](https://npm.io/package/juice.md) ^5.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [cheerio](https://npm.io/package/cheerio.md) ^0.20.0
- [is-html](https://npm.io/package/is-html.md) ^1.0.0
- [winston](https://npm.io/package/winston.md) ^2.2.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [cli-table](https://npm.io/package/cli-table.md) ^0.3.1
- [nodemailer](https://npm.io/package/nodemailer.md) ^5.1.1
- [xmlbuilder](https://npm.io/package/xmlbuilder.md) ^8.2.2
- [event-stream](https://npm.io/package/event-stream.md) 3.3.4
- [special-html](https://npm.io/package/special-html.md) 0.0.1
- [web-resource-inliner](https://npm.io/package/web-resource-inliner.md) ^4.2.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

- 0.0.2 (latest) — 2019-03-19
- 0.0.1 — 2019-03-19

## README

email-builder-core-min
==================

Email builder core for export into other projects.

This is a forked version of email-builder-core (https://github.com/Email-builder/email-builder-core) with some updates to it and one less perk.

This version does _not_ include the litmus api, and has been updated to use Gulp 4.

# Constructor

### `new EmailBuilder(options)`

Example:
```javascript
const EmailBuilder = require('email-builder-core-min');
const emailBuilder = new EmailBuilder({ encodeSpecialChars: true });
```

# Options

The following options may support all available methods of EmailBuilder.  However there some that are only needed for a particular method.

**options.encodeSpecialChars**
Type: `Boolean`
Default: `false`
Supported Method(s): `All`

Encodes special characters to their HTML numerical form e.g. © --> &amp;#169;

**options.relativePath**
Type: `String`
Default: `''`
Supported Method(s): `emailBuilder.inlineCss`

This option must be set when passing a Buffer or a String to the `inlineCss` method. That way it has a relative path to any css files. The path should be whatever directory your src file is in.

**options.emailTest**
Type: `Object`
Default: `{}`
Properties: `to`, `from`, `subject`, `nodemailer`
Supported Method(s): `emailBuilder.sendEmailTest`


The optional `nodemailer` property is an object that has `transporter` and `defaults` properties. These get passed to the [nodemailer.createTransport()](https://github.com/nodemailer/nodemailer#setting-up) method. You can use [transport plugins](https://github.com/nodemailer/nodemailer#send-using-a-transport-plugin) or play with the default [SMTP](https://github.com/nodemailer/nodemailer#set-up-smtp) options for the `nodemailer.transporter` property

Example:

```javascript

  emailTest : {

  // Email to send to
  to : 'toEmail@email.com',

  // Email sent from
  from: 'fromEmail@email.com',

  // Your email Subject
  subject : 'Email Subject',

  // Optional
  nodemailer: {
    transporter: {
      service: 'gmail',
      auth: {
        user: 'gmailuser',
        pass: 'gmailpass'
      }
    },
    defaults: {}
  }
}
```

**options.juice**
Type: `Object`
Default: `{}`
Supported Properties: `extraCss`, `applyWidthAttributes`, `applyAttributesTableElements`
Supported Method(s): `emailBuilder.inlineCss`

View [Juice](https://github.com/Automattic/juice#options) options

**options.cheerio**
Type: `Object`
Default: `{}`

View [Cheerio](https://github.com/cheeriojs/cheerio) options.



# Methods

All methods return a promise, the underlying promise library we use is [Bluebird](https://github.com/petkaantonov/bluebird/blob/master/API.md).

Methods can be used seperately, or chained together using the `.then` method.

If you're not familiar with promises, instead of using a callback, you chain a `.then` method to get the results.


### `emailBuilder.inlineCss(file/html/buffer)`

Inlines css from embedded or external styles. It'll automatically remove any link or style tags unless one of the data attributes below are used.

**Arguments**

`file` - String containing path to file
`string` - String of HTML
`buffer` - Buffer of HTML

**HTML data attributes**
There are two supported data attributes that you can apply to \<style\> or \<link\> tags that have special meaning:

`data-embed`
  - use on \<style\> or \<link\> tags if you want styles to be embedded in the \<head\> of the final output. Does not inline css

`data-embed-ignore`
  - use on \<link\> tags to preserve them in the \<head\>. Does not inline or embed css

Example:
```javascript
emailBuilder.inlineCss('path/to/file.html')
    .then(html => {
        console.log(html);
    });
```

### `emailBuilder.sendEmailTest(html)`

Send email tests to yourself

**Arguments**

`html` - String/Buffer of HTML

Example:
```javascript
const fs = require('fs');
const file = fs.readFileSync('path/to/file.html');
emailBuilder.sendEmailTest(file)
  .then(html => {
    console.log(html);
  });
```

# Complete Example

**input.html**
```html
<!DOCTYPE html>
<html>
<head>
  <!-- styles will be inlined -->
  <link rel="stylesheet" type="text/css" href="../css/styles.css">

  <!-- styles will be embedded -->
  <link rel="stylesheet" type="text/css" href="../css/otherStyles.css" data-embed>

  <!-- link tag will be preserved and styles will not be inlined or embedded -->
  <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' data-embed-ignore>

  <!-- styles will be inlined -->
  <style>
    p { color: red; }
  </style>

  <!-- styles will be embedded -->
  <style data-embed>
    h1 { color: black; }
  </style>
</head>
<body>
  <h1>Heading</h1>
  <p>Body</p>
</body>
</html>
```

**main.js**
```javascript
const fs = require('fs');
const EmailBuilder = require('email-builder-core-min');
const options = {
  encodeSpecialChars: true,
  emailTest: {...}
};
const emailBuilder = new EmailBuilder(options);
const src = process.cwd() + '/input.html';

emailBuilder.inlineCss(src)
    .then(emailBuilder.sendEmailTest)
    .then(html => {
        // can write files here
        fs.writeFileSync(process.cwd() + '/out.html', html);
    })
    catch(err => {
        console.log(err);
    });
```

**out.html**
```html
<!DOCTYPE html>
<html>
<head>
  <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
  <style>
    h1 { color: black; }
  </style>
</head>
<body>
  <h1>Heading</h1>
  <p style="color: red">Body</p>
</body>
</html>
```

# Testing

`gulp test` - Runs **jshint** and **mocha** tests
`gulp inline` - Inlines css from **test/fixtures/input** directory and creates the **test/fixtures/output** directory. Run if you add/update any fixtures in the **test/fixtures/input** directory.

# Thanks to
The original Email Builder Core Team:

Jeremy Peter (https://github.com/jeremypeter)

Steve Miller (http://www.stevenjohnmiller.com.au)

[Juice](https://github.com/Automattic/juice) for compiling.

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