# rock-emails

> ## Instalation

Latest version **1.0.0** (published 2020-04-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install rock-emails
pnpm add rock-emails
yarn add rock-emails
bun add rock-emails
```

## 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 | 1.0.0 |
| Published | 2020-04-02 |
| First published | 2020-04-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | RockOS Team |
| Maintainers | vitorfreitas |

## Links

- npm: https://www.npmjs.com/package/rock-emails
- npm.io page: https://npm.io/package/rock-emails

## Dependencies (3)

- [verror](https://npm.io/package/verror.md) ^1.10.0
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.649.0
- [@sendgrid/mail](https://npm.io/package/@sendgrid/mail.md) ^6.5.5

## Recent versions

- 1.0.0 (latest) — 2020-04-02

## README

# Rock Emails

## Instalation

`npm i rock-emails`

## Usage

```ts
import { EmailSender } from 'rock-emails'

const emailSender = new EmailSender({ type: 'sendgrid' })

emailSender.authenticate(...)
emailSender.send(...)
emailSender.sendWithTemplate(...)
emailSender.createTemplate(...)
```

Before using `.send`, `.sendWithTemplate` or `.createTemplate` you should first
authenticate yourself using `.authenticate` with the correct parameters for your
strategy.

## Available strategies

- [SendGrid](https://github.com/sendgrid/sendgrid-nodej://github.com/sendgrid/sendgrid-nodejs)
- [AWS SES](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html)

## Methods

### `.authenticate`

Authenticate yourself using the strategies' authentication method. Available
authentication methods are [AmazonAuth]() and [SendGridAuth]().

### `.send`

Once authenticated, you can send plain text emails to users.

```ts
import { EmailParams } from 'rock-emails'

const message: EmailParams = {
  from: 'john@doe.com', 
  to: ['jane@doe.com'],
  // bcc?: string[]
  // cc?: string[]
  subject: 'just passing by', 
  message: 'hey friend, how are you doing?'
}

emailSender.send(message)
```

### `.sendWithTemplate`

Similar to `.send`, but you can inform an template id and the replacements to
template binds.

```ts
import { EmailParams } from 'rock-emails'

const message: EmailParams = {
  from: 'john@doe.com', 
  to: ['jane@doe.com'],
  // bcc?: string[]
  // cc?: string[]
  subject: 'just passing by', 
  message: {
    name: 'John doe'
  },
  template: 'my-template-id-001'
}

emailSender.sendWithTemplate(message)
```

### `.createTemplate`

Creates a new template on your strategy API.

```ts
import { TemplateParams } from 'rock-emails'

const template: TemplateParams = {
  name: 'my awesome template',
  html: '<h1>{{name}}</h1>',
  subject: 'some subject', // optional
  text: 'some text' // optional
}

emailSender.createTemplate(template)
```

## License

[MIT]()

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