Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@suddenly/mailer

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

Install

npm i @suddenly/mailer

DownloadsWeekly Downloads

12

Version

1.2.1

License

ISC

Unpacked Size

10.7 kB

Total Files

5

Last publish

Collaborators

  • avatar