@suddenly/mailer
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

@suddenly/mailer

A simple templated email sender. Works with SES credentials or a SendGrid API Key

Usage

With SES

In your user panel, generate an access key and a secret (and make sure they have permission to send emails with SES).

import Mailer from '@suddenly/mailer';

Mailer.initialize({
  sesKey: process.env.SES_KEY,
  sesSecret: process.env.SES_SECRET,
  templatePath: 'src/server/notifications'
});

// Any other method called on the Mailer will be treated as an email.
// The name of the method will be used as the template name.
// eg. This will look in the `templatePath` directory for files named `requestSignIn.html.ejs` and `requestSignIn.text.ejs`
Mailer.requestSignIn('someone@test.com', 'Subject', {
  someTemplateVariable: 'some value',
  anotherTemplateVariable: 'some other value'
});

With SendGrid

First up, you'll need a SendGrid API Key.

Then you can use it like this:

import Mailer from '@suddenly/mailer';

Mailer.initialize({
  sendGridAPIKey: process.env.SENDGRID_API_KEY,
  defaultFromAddress: 'no-reply@your-domain.com',
  templatePath: 'src/server/notifications'
});

// Any other method called on the Mailer will be treated as an email.
// The name of the method will be used as the template name.
// eg. This will look in the `templatePath` directory for files named `requestSignIn.html.ejs` and `requestSignIn.text.ejs`
Mailer.requestSignIn('someone@test.com', 'Subject', {
  someTemplateVariable: 'some value',
  anotherTemplateVariable: 'some other value'
});

Contributors

Readme

Keywords

Package Sidebar

Install

npm i @suddenly/mailer

Weekly Downloads

0

Version

1.2.1

License

ISC

Unpacked Size

10.7 kB

Total Files

5

Last publish

Collaborators

  • nathanhoad