1.0.0 • Published 4 years ago

rock-emails v1.0.0

Weekly downloads
5
License
ISC
Repository
-
Last release
4 years ago

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