The SendGrid wrapper helps to send an email with a dynamic template.

Source Code

npm version Node.js CI code style: prettier license


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.


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 following:


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);

    to: '',
    from: '',
    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(() => {})

For more use cases, please see Sendgrid use cases.

Email settings

Property Name Type Description
apiKey string SendGrid API Key
prefix string The prefix used as a namespace to create template name.


# Export your SendGrid API Key

# Run all tests
npm test


MIT © t-ho