Socket
Socket
Sign inDemoInstall

rest-email-api

Package Overview
Dependencies
210
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-email-api

A REST API that sends both ad-hoc and templated emails.


Version published
Maintainers
1
Weekly downloads
2

Weekly downloads

Readme

Source

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

Keywords

FAQs

Last updated on 17 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc