Send an email to a user.

import sendgrid from '@sendgrid/mail';


export default async (req, res) => {
  try {
    await sendgrid.send({
      to: '',
      from: '',
      subject: 'Serverless Functions',
      text: 'Hello, world!'
  } catch (error) {
    return res.status(error.statusCode || 500).json({ error: error.message });

  return res.status(200).json({ error: '' });



Create SendGrid Account

First, create a SendGrid account. Then, generate an API key.


Add Sender Authentication

To protect against spam, SendGrid requires customers to verify their Sender Identities.

  1. Navigate to Sender Authentication.
  2. Click "Create New Sender".
  3. Fill out the form and click "Create".
  4. Verify your email address.

Add Environment Variables

To securely access the API, we need to include the secret with each request. We also do not want to commit secrets to git. Thus, we should use an environment variable. Learn how to add environment variables in Vercel.

Proud member of the Weird Wide Webring.