# Quickstart: Next.js

> Send email from a Next.js app with Email Fast: a route handler or server action with @email-fast/nodejs, environment setup, and safe testing with sandbox keys.

Canonical: https://emailfast.dev/docs/quickstart-nextjs

## 1. Install & configure

```bash
npm install @email-fast/nodejs
```

```bash
# .env.local
EMAILFAST_API_KEY=ef_sandbox_...   # swap to ef_live_… at launch
```

## 2. A route handler

```ts
// app/api/welcome/route.ts
import { EmailFast } from "@email-fast/nodejs";
import { NextResponse } from "next/server";

const ef = new EmailFast({ apiKey: process.env.EMAILFAST_API_KEY!, baseUrl: "https://api.emailfast.dev" });

export async function POST(req: Request) {
  const { email, name } = await req.json();

  const { id } = await ef.send({
    to: email,
    subject: "Welcome!",
    html: "<h1>Hi {{name}}</h1>",
    data: { name },
    idempotency_key: `welcome-${email}`, // a double-submit can't double-send
  });

  return NextResponse.json({ id });
}
```

## 3. Or a server action

```ts
// app/actions.ts
"use server";
import { EmailFast } from "@email-fast/nodejs";

const ef = new EmailFast({ apiKey: process.env.EMAILFAST_API_KEY!, baseUrl: "https://api.emailfast.dev" });

export async function sendWelcome(formData: FormData) {
  await ef.send({
    to: String(formData.get("email")),
    subject: "Welcome!",
    html: "<p>You're in.</p>",
  });
}
```

## Frontend-only instead?

If you have no server at all (static export, marketing page), don't ship a secret to
the browser — use the [browser SDK](/docs/quickstart-browser) with a public key:
a browser SDK with EmailJS-compatible endpoints — the recipient always comes from the server-stored template, never from the request, so a public key in your frontend can't be abused to spam arbitrary addresses.

## Next

- [Webhooks for delivery events](/features/webhooks)
- [Templates & MJML](/features/templates)
- [The sandbox in CI](/features/sandbox)
