# punch-emailer

> Module for send emails based on nodemailer.

Latest version **0.0.1** (published 2016-07-20) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2016-07-20 |
| First published | 2016-07-20 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+15 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | punchagency |

## Links

- npm: https://www.npmjs.com/package/punch-emailer
- npm.io page: https://npm.io/package/punch-emailer

## Dependencies (4)

- [ejs](https://npm.io/package/ejs.md) ^2.4.1
- [bluebird](https://npm.io/package/bluebird.md) ^2.9.34
- [nodemailer](https://npm.io/package/nodemailer.md) ^2.3.2
- [email-templates](https://npm.io/package/email-templates.md) ^2.3.0

## Recent versions

- 0.0.1 (latest) — 2016-07-20

## README

# punch-emailer
Send emails

## Config
*  from - email address that used to send emails
*  templateDir - dir with email templates
*  nodemailerConf - nodeemail config see  https://github.com/nodemailer/nodemailer
*  logger - function that can log sent emails  (example - console.log)

## Templates
  see email-templates documentation https://github.com/niftylettuce/node-email-templates

```
<div>
  Hello, <%= user.firstName + ' ' + user.lastName %>
  Reset password link <a href="<%- verificationLink %>" target="_blank">link</a>
  Or just copy the link: <%- verificationLink %>
</div>

```

## Usage
```javascript
'use strict';
const PunchEmailer = require('punch-emailer');
const path = require('path');


const smtpConfig = {
  host:  process.env.SMTP_HOST || 'xxxxx',
  port:  process.env.SMTP_PORT || 465,
  secure:  process.env.SMTP_SECURE || true, // use SSL
  auth: {
    user:  process.env.SMTP_USER || 'xxxxx',
    pass:  process.env.SMTP_PASS || 'xxxxx'
  }
};

const HOST = process.env.HOST || ' http://xxxxx.com/';
const querystring = require("querystring");
const templateDir = path.join(__dirname, 'templates');

const config = {
  from:  process.env.SMTP_FROM || 'no-reply@xxxxx.com',
  templateDir: templateDir,
  nodemailerConf : smtpConfig
};



class Emailer extends PunchEmailer {
  sendEmailVerification(to, data){
    let queryParams = querystring.stringify({email : to, code : data.verificationCode});
    data.verificationLink =  HOST + '#/confirm-email?' + queryParams;
    return this.sendTemplate(
      to,
      'Email verification',
      'email-verification',
      data
    );
  };

  sendResetPassword(to, data){
    let queryParams = querystring.stringify({email : to, code : data.verificationCode});
    data.verificationLink =  HOST + '#/reset-password?' + queryParams;
    return this.sendTemplate(
      to,
      'Reset password',
      'reset-password',
      data
    );
  };
};

module.exports = new Emailer(config);
```


```javascript

const emailer = require('./emailer');

emailer.sendEmailVerification('test@te.st', {
    user : {
      firstName : 'Jastin',
      lastName : 'Hastin'
    },
    verificationCode : 'xxx-xxx-xxxx'
    })
```

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