Email

How to send email on Vercel

On Vercel, send email through an HTTP API in Node.js or Edge, or await SMTP in Node.js functions.

An HTTP email API works in both Vercel's Node.js and Edge runtimes and is Vercel's recommended path. SMTP can work in Node.js if you await the send within the function's execution limits. It cannot run in Edge, which lacks Node's TCP modules.

What does SMTP require on Vercel?

In a Node.js function, await the SMTP send before returning your response so the exchange finishes before the function stops. The send must complete within the function's duration limit. Vercel allows outbound SMTP on ports 465 and 587; port 25 is blocked. Edge lacks the Node.js net module, so SMTP libraries cannot open a TCP connection there.

How do you send email from a Next.js Route Handler?

Create a Route Handler at app/api/send/route.ts. It reads the API key from an environment variable and calls the email API. Using the Bird Node SDK:

// app/api/send/route.ts
import { BirdClient } from "@messagebird/sdk";

export const runtime = "nodejs";

const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });

export async function POST(request: Request) {
  const { to } = await request.json();

  const { data, error } = await bird.email
    .send({
      from: "you@yourdomain.com",
      to: [to ?? "delivered@bird.dev"],
      subject: "Hello from Node",
      html: "<p>It works.</p>",
    })
    .safe();

  if (error) {
    return Response.json({ error: error.message }, { status: 502 });
  }

  return Response.json({ id: data.id });
}

Set BIRD_API_KEY in the Vercel project's environment variables so it is available at runtime and never committed. The delivered@bird.dev sandbox address always accepts mail, which makes the first deploy easy to verify.

Edge runtime or Node runtime?

The export const runtime line picks which one runs your handler. Because the SDK and fetch both work in either, you can choose based on your other needs:

Node runtimeEdge runtime
DefaultYesOpt-in
Node APIs (net, fs)AvailableNot available
Cold startSlowerFaster
SMTP librariesAwait within the duration limitCannot run at all
HTTP email API (fetch)WorksWorks

If you only call an HTTP API, the Edge runtime gives you faster cold starts. If you depend on a Node-only package elsewhere in the handler, stay on Node. Either way the email send is the same fetch-based call.

Send it with Bird

The handler above already uses the canonical snippet. The shape is the same anywhere you run JavaScript:

import { BirdClient } from "@messagebird/sdk";

const bird = new BirdClient({ apiKey: process.env.BIRD_API_KEY! });

const { data, error } = await bird.email
  .send({
    from: "you@yourdomain.com",
    to: ["delivered@bird.dev"],
    subject: "Hello from Node",
    html: "<p>It works.</p>",
  })
  .safe();

If you build your email bodies as components, React Email renders them to the HTML this call expects. For the wider picture of where email code belongs, see sending email with JavaScript.

FAQ

Can I use Nodemailer on Vercel?

Yes, in Node.js functions: await the send before returning the response, and finish within the function's duration limit. Nodemailer cannot run in Edge because the runtime lacks Node's net module.

Where do I store my API key on Vercel?

In the project's environment variables, set in the Vercel dashboard or CLI. The handler reads it with process.env, so it stays on the server and out of your repository.

Edge or Node runtime for sending email?

Either works for an HTTP API call. Edge has faster cold starts; Node is required if your handler also uses Node-only packages.

Vercel and an HTTP email API are a natural pair. The email product overview and the sending email guide cover the rest of the surface.

Peak traffic and backlog recovery determine the sending capacity your application needs from a transactional email service.

Build on the same network.

A test API key is yours immediately. Production unlocks when you add a payment method and verify a sender.

Your next idea.
Ready to connect.