Last active
June 6, 2021 07:20
-
-
Save chadmuro/83d5b517cdc2b11a0b05a8907e855708 to your computer and use it in GitHub Desktop.
Next.js SendGrid
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 mail = require('@sendgrid/mail'); | |
| mail.setApiKey(process.env.SENDGRID_API_KEY); | |
| export default async (req, res) => { | |
| const body = JSON.parse(req.body); | |
| const message = ` | |
| Name: ${body.name}\r\n | |
| Email: ${body.email}\r\n | |
| Message: ${body.message} | |
| `; | |
| const data = { | |
| to: 'SENDER-EMAIL', | |
| from: 'RECEIVER-EMAIL', | |
| subject: `New message from ${body.name}`, | |
| text: message, | |
| html: message.replace(/\r\n/g, '<br />'), | |
| }; | |
| await mail.send(data); | |
| res.status(200).json({ status: 'OK' }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment