rock-packages

1.0.2 • Public • Published

Rock Emails

Instalation

npm i rock-emails

Usage

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

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.

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.

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.

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

Readme

Keywords

none

Package Sidebar

Install

npm i rock-packages

Weekly Downloads

1

Version

1.0.2

License

ISC

Unpacked Size

21.2 kB

Total Files

17

Last publish

Collaborators

  • vitorfreitas