npm i rock-emails
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.
Authenticate yourself using the strategies' authentication method. Available authentication methods are AmazonAuth and SendGridAuth.
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)
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)
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)