rest-email-api

1.0.11 • Public • Published

rest-email-api

Welcome to rest-email-api! Now sending emails is as easy as sending an HTTP request.

This email API supports sending templated emails and non-templated emails through a POST body.

Great for sending password reset emails to users, account validation emails, or MFA confirmation emails.

Installation

  npm install rest-email-api

Here's an example!

Step One: Start the server like so:

// index.js
const emailService = require('rest-email-api')
const path = require('path')
 
emailService.runEmailApi({
  port: 3000,
  secretKey: 'ANY_SECRET_KEY', // Any super long, random, and hard to guess key
  emailUser: 'email@youremail.com',
  emailAuth: {
    // See nodemailer create transporter method at nodemailer.com/about/#/example for more information.
    service: 'gmail',
    auth: {
      user: 'email@youremail.com',
      pass: 'your_password'
    }
  },
  templateDirectory: path.join(__dirname, './templates')
  })

Step Two: Set up a folder to store the templates.

For this example, let's set up a "congrats" template to congratulate our recipient for a recent purchase.

.
├── index.js
└── templates
    └── congrats
        ├── html.pug

html.pug

p Congratulations! Enjoy the purchase of your new:
p #{itemId}

Step Three: Send your HTTP request!

Below is an example documented via Postman.

For a templated email:

  • The request header should have your authorization secret key.

Template Email Request Header

  • Set the template folder name that the service should use.

Template Email Request Params

  • Then, your POST body should look something like this:

Template Email Request POST body

  • And finally, your recipient can enjoy their new email.

Final Resulting Templated Email

For an ad-hoc/on the fly email made without a template:

  • The request header should have your authorization secret key.

Ad-Hoc Email Request Header

  • The only thing left to do is to set your POST body like so:

Ad-Hoc Email Request POST body

  • And then in your inbox is a shiny new email.

Final Resulting Ad-Hoc Email

Package Sidebar

Install

npm i rest-email-api

Weekly Downloads

1

Version

1.0.11

License

MIT

Unpacked Size

792 kB

Total Files

18

Last publish

Collaborators

  • gina-shin