Skip to content

Instantly share code, notes, and snippets.

@sendgrid-gists
Last active September 28, 2020 19:53
Show Gist options
  • Save sendgrid-gists/069d788aefb7853706f424cbdfd7ee3c to your computer and use it in GitHub Desktop.
Save sendgrid-gists/069d788aefb7853706f424cbdfd7ee3c to your computer and use it in GitHub Desktop.
v3 "Hello World" for email, using SendGrid with Node.js.
// using Twilio SendGrid's v3 Node.js Library
// https://github.com/sendgrid/sendgrid-nodejs
javascript
const sgMail = require('@sendgrid/mail')
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
const msg = {
to: 'test@example.com', // Change to your recipient
from: 'test@example.com', // Change to your verified sender
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
}
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