Skip to content

Instantly share code, notes, and snippets.

@wgrisa
Created July 18, 2019 13:21
Show Gist options
  • Select an option

  • Save wgrisa/5c7f5e20d845fc1fa0c181279cd3927f to your computer and use it in GitHub Desktop.

Select an option

Save wgrisa/5c7f5e20d845fc1fa0c181279cd3927f to your computer and use it in GitHub Desktop.
const sendgridClient = require('@sendgrid/client')
const sendEmail = (message, res) => {
sendgridClient.setApiKey(process.env.SENDGRID_KEY)
const request = {
method: 'POST',
url: '/v3/mail/send',
body: message,
}
sendgridClient
.request(request)
.then(([response, body]) => {
console.log('Response: ', response.statusCode)
console.log('Body: ', body)
res.sendStatus(response.statusCode)
})
.catch((error) => {
console.log('Error sending email: ', error)
res.status(error.code).send(error.message)
})
}
module.exports = sendEmail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment