Skip to content

Instantly share code, notes, and snippets.

@marshyon
Created August 26, 2022 18:07
Show Gist options
  • Save marshyon/75d4c6c94f58570ec1f2088e03d3eef9 to your computer and use it in GitHub Desktop.
Save marshyon/75d4c6c94f58570ec1f2088e03d3eef9 to your computer and use it in GitHub Desktop.
use sendgid api to send a mail using a preconfigured template in the sendgrid web console
require('dotenv').config()
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
to: process.env.RECIPIENT,
from: process.env.SENDER,
templateId: process.env.SENDGRID_TEMPLATE_KEY,
dynamicTemplateData: {
user: 'John Doe',
message: 'call the president ...',
},
};
sgMail
.send(msg)
.then(() => {
console.log('Email sent')
})
.catch((error) => {
console.error(error)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment