Prerequisites

To get the most out of this guide, you’ll need to:

Make sure you have the latest version of the Vercel CLI installed.

1. Create a Next.js function

Create a route file under app/api/send/route.ts if you’re using the App Router.

route.ts
const RESEND_API_KEY = 're_123456789';

export async function POST() {
  const res = await fetch('https://api.resend.com/emails', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${RESEND_API_KEY}`,
    },
    body: JSON.stringify({
      from: 'Acme <onboarding@resend.dev>',
      to: ['delivered@resend.dev'],
      subject: 'hello world',
      html: '<strong>it works!</strong>',
    }),
  });

  if (res.ok) {
    const data = await res.json();
    return Response.json(data);
  }
}

2. Send email locally

Run function locally:

npx next dev

Open the endpoint URL to send an email: http://localhost:3000/api/send

3. Send email in production

Deploy function to Vercel:

vercel

Open the endpoint URL to send an email: https://your-project.vercel.app/api/send

4. Try it yourself

Vercel Functions Example

See the full source code.