Created
August 26, 2022 18:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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