# hof-emailer

> A service for generating and sending html and raw emails for use with HOF services

Latest version **2.1.1** (published 2021-05-13) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install hof-emailer
pnpm add hof-emailer
yarn add hof-emailer
bun add hof-emailer
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2021-05-13 |
| First published | 2016-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 46.4 KB |
| Known vulnerabilities | 0 (+22 in 1 direct dependencies) |
| Install scripts | no |
| Author | UKHomeOffice |
| Maintainers | mohameduwais, cmedland, maxosully, sarahjaneluff, lennym, easternbloc, josephchapman, joefitter, coupey, sulthan-ahmed, andrew.moody.ho, alexfranklin, aswann, robertdeniszczyc2, agraham19, aaron.robinson |

## Links

- npm: https://www.npmjs.com/package/hof-emailer
- Homepage: https://github.com/UKHomeOffice/hof-emailer
- Issues: https://github.com/UKHomeOffice/hof-emailer/issues
- npm.io page: https://npm.io/package/hof-emailer

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) ^2.6.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [hogan.js](https://npm.io/package/hogan.js.md) ^3.0.2
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.4.16
- [nodemailer-ses-transport](https://npm.io/package/nodemailer-ses-transport.md) ^1.5.0
- [nodemailer-smtp-transport](https://npm.io/package/nodemailer-smtp-transport.md) ^2.7.2
- [nodemailer-stub-transport](https://npm.io/package/nodemailer-stub-transport.md) ^1.1.0

## Recent versions

- 2.1.1 (latest) — 2021-05-13
- 1.6.2 (version-1) — 2017-05-22
- 2.1.0 — 2017-10-27
- 2.0.0 — 2017-03-10
- 1.6.1 — 2016-12-13
- 1.6.0 — 2016-12-06
- 1.5.1 — 2016-11-22
- 1.5.0 — 2016-11-18
- 1.4.0 — 2016-11-18
- 1.3.1 — 2016-11-16
- 1.3.0 — 2016-11-10
- 1.2.0 — 2016-11-07
- 1.1.0 — 2016-11-03
- 1.0.0 — 2016-10-27

## README

# HOF Emailer

An emailer service for HOF applications.

## Installation

```bash
$ npm install hof-emailer --save
```

## Usage

```js
// first create an emailer instance
const Emailer = require('hof-emailer');
const emailer = new Emailer({
  from: 'sender@example.com',
  transport: 'smtp',
  transportOptions: {
    host: 'my.smtp.host',
    port: 25
  }
});

// then you can use your emailer to send emails
const to = 'recipient@example.com';
const body = 'This is the email body';
const subject = 'Important email!'
emailer.send(to, body, subject)
  .then(() => {
    console.log(`Email sent to ${to}!`);
  });
```

## Options

- `from`: <String>: Address to send emails from. Required.
- `transport`: <String>: Select what mechanism to use to send emails. Defaults: 'smtp'.
- `transportOptions`: <Object>: Set the options for the chosen transport, as defined below. Required.
- `layout`: <String>: Optional path to use a custom layout for email content.

## Transports

The following transport options are available:

### `smtp`

[nodemailer-smtp-transport](https://github.com/andris9/nodemailer-smtp-transport)

#### Options

- `host` <String>: Address of the mailserver. Required.
- `port` <String|Number>: Port of the mailserver. Required.
- `ignoreTLS` <Boolean>: Defaults to false.
- `secure` <Boolean>: Defaults to true.
- `auth.user` <String>: Mailserver authorisation username.
- `auth.pass` <String>: Mailserver authorisation password.

### `ses`
[nodemailer-ses-transport](https://github.com/andris9/nodemailer-ses-transport)

#### Options

- `accessKeyId` <String>: AWS accessKeyId. Required.
- `secretAccessKey` <String>: AWS accessKeyId. Required.
- `sessionToken` <String>
- `region` <String>. Defaults to 'eu-west-1'.
- `httpOptions` <String>
- `rateLimit` <String>
- `maxConnections` <String>

### `debug`

A development option to write the html content of the email to a file for inspection.

`transport: 'debug'`

#### debug options

- `dir` <String>: The location to save html to. Default: `./.emails`. This directory will be created if it does not exist.
- `open` <Boolean>: If set to true, will automatically open the created html file in a browser.

#### debug example

```
transport: 'debug'
transportOptions: {
  dir: './emails',
  open: true
}
```
### `stub`

Disables sending email. No options are required.

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