# mfdc-email

> MFDC standard wrapper library around Nodemailer

Latest version **2.0.0** (published 2016-09-12) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install mfdc-email
pnpm add mfdc-email
yarn add mfdc-email
bun add mfdc-email
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-09-12 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+13 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matt Carter |
| Maintainers | hash-bang |
| Keywords | mfdc, email |

## Links

- npm: https://www.npmjs.com/package/mfdc-email
- Repository: https://github.com/MomsFriendlyDevCo/mfdc-email
- Homepage: https://github.com/MomsFriendlyDevCo/mfdc-email#readme
- Issues: https://github.com/MomsFriendlyDevCo/mfdc-email/issues
- npm.io page: https://npm.io/package/mfdc-email

## Dependencies (6)

- [colors](https://npm.io/package/colors.md) ^1.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.13.1
- [mustache](https://npm.io/package/mustache.md) ^2.2.1
- [nodemailer](https://npm.io/package/nodemailer.md) ^2.4.2
- [nodemailer-mailgun-transport](https://npm.io/package/nodemailer-mailgun-transport.md) ^1.0.2
- [nodemailer-sendmail-transport](https://npm.io/package/nodemailer-sendmail-transport.md) ^1.0.0

## 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.0 (latest) — 2016-09-12
- 1.2.0 — 2016-07-26
- 1.1.2 — 2016-07-08
- 1.1.1 — 2016-07-08
- 1.1.0 — 2016-05-26
- 1.0.0 — 2016-05-26

## README

MFDC-Email
==========
This module is a thin wrapper around the [nodemailer](https://github.com/nodemailer/nodemailer) module which loads its config from the locations specified in the [MFDC Node project standard layout](https://github.com/MomsFriendlyDevCo/Momsronomicon/blob/master/style-node.md).


Quickstart guide
----------------
If you're project is already setup with appropriate config (see [Expected Config](#expected-config)) you should just be able to call the module as follows:


```javascript
var email = require('mfdc-email');

// NOTE: You have to create a new instance

email()
	.send({
		to: 'someone@somewhere.com',
		from: 'noreply@domain.com',
		subject: 'Plain email test via mfdc-email',
		text: 'Hello World',
	}, function(err, res) {
		// Do something with the result
	});
```

or using chainable methods:

```javascript
var email = require('mfdc-email');

email()
	.to('Joe Random <joe@random.com>')
	.subject('HTML chainable method email test via mfdc-email')
	.html('<p>Hello <b>World</b></p>')
	.send(function(err, res) {
		// Do something with the result
	});
```

Using template views
--------------------
Specifying the `template` property either as a key in the `send()` object or via the chainable `.template()` method, will specify the file on disk to be used when composing the email.

* The type of email to send is determined by the file extension. `.txt` files are plain text and `.html` files are rich content.
* All templates are rendered via [Mustache](http://mustache.github.io) with the parameters used taken from the `templateParams` option.
* Mustache will automatically escape all variables. If you wish to use an unsecaped variable like a URL encase it in three levels of brackets rather than two e.g. `{{{url}}}`

```javascript
var email = require('mfdc-email');

email()
	.to('Joe Random <joe@random.com>')
	.subject('Password Recovery')
	.template(config.root + '/views/emails/password-recovery.txt')
	.templateParams({
		name: 'Joe Random',
		signoff: 'The MFDC team',
	})
	.send();
```


API
===

send(email, callback)
---------------------
Dispatch an email. This is as functionally similar to the Nodemailer `send()` command as possible. Use this if lower level access is required.

to, from, cc, bcc, subject, text, html()
----------------------------------------
All these methods are chainable:

```javascript
var email = require('mfdc-email');

email()
	.to('someone@somewhere.com')
	.subject('something')
	.send();
```


init()
------
Reinitialize the mail transport and reset all defaults to the global values.


Expected Config
---------------
This module expects the following `global.config` / `global.app.config` variables to be specified to operate:

| Method    | Key                              | Type           | Description |
|-----------|----------------------------------|----------------|-------------|
| All       | `email.enabled`                  | Boolean        | Temporarily disable the sending of email. If falsy this will message to the console and not actually send anything |
|           | `email.method`                   | String         | What transport profile to use, see `init()` for details |
|           | `email.{to,from,subject,cc,bcc}` | String / Array | Default fields to use if unspecified |
|           | `email.template`                 | String         | Read a template file and render it as the email content |
| Mailgun   | `mailgun.apiKey`                 | String         | The API key for the Mailgun profile |
|           | `mailgun.domain`                 | String         | The Mailgun domain, usually something like 'acme.com' (no 'http://' prefix or Mailgun suffix) |

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