Skip to content

Instantly share code, notes, and snippets.

@chadmuro
Last active June 6, 2021 07:20
Show Gist options
  • Select an option

  • Save chadmuro/83d5b517cdc2b11a0b05a8907e855708 to your computer and use it in GitHub Desktop.

Select an option

Save chadmuro/83d5b517cdc2b11a0b05a8907e855708 to your computer and use it in GitHub Desktop.
Next.js SendGrid
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