Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sendgrid-template-helper

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sendgrid-template-helper

The Sendgrid wrapper helps to send an email with a dynamic template stored on disk.

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22
increased by266.67%
Maintainers
1
Weekly downloads
 
Created
Source

npm version Node.js CI code style: prettier license

sendgrid-template-helper

The Sendgrid wrapper helps to send an email with a dynamic template stored on disk. It tries to create a dynamic template on the Sendgrid server via Sendgrid API v3, then caches the template ID locally for later uses.

Installation

Install sendgrid-template-helper via NPM:

npm install --save sendgrid-template-helper
# or
yarn add sendgrid-template-helper

Obtain a Sendgrid API Key

Create your Sendgrid API Key from SendGrid

Setup Environment variables

In your development environment, export your Sendgrid API Key as follow:

export SENDGRID_API_KEY=YOUR_API_KEY

Send email

To send an email with dynamic email template (template is on your disk):

const path = require("path");
const Email = require("sendgrid-template-helper");

const settings = {
  apiKey: process.env.SENDGRID_API_KEY,
  prefix: "your_app_name_",
};

const email = new Email(settings);

email
  .send({
    to: "user@tdev.app",
    from: "admin@tdev.app",
    subject: `[Test] Sendgrid template helper`,
    templatePath: path.resolve(__dirname, "./dynamic-email-template.html"), // absolute path to your template
    dynamicTemplateData: {
      // your dynamic template data
      username: "user",
    },
  })
  .then(() => {})
  .catch(console.log);

For more use cases, please see Sendgrid use cases.

Email settings

Property NameTypeDescription
apiKeystringSendGrid API Key
prefixstringThe prefix used as namespace to create template name.

Testing

# Export your SendGrid API Key
export SENDGRID_API_KEY=YOUR_API_KEY

# Run all tests
npm test

License

MIT © t-ho

Keywords

FAQs

Package last updated on 14 Mar 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc