Created
July 18, 2019 13:21
-
-
Save wgrisa/5c7f5e20d845fc1fa0c181279cd3927f to your computer and use it in GitHub Desktop.
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
| 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