Send email from the server side of a Next.js app: a server action for form submissions, or a route handler when another system calls your endpoint. The SendPanda SDK supports Node.js 22 or newer, so use the Node.js runtime rather than the Edge runtime.
1. Install the SDK and add a key
npm install @sendpanda/sdkCreate a Send emails key in your project and keep it in your server environment as SENDPANDA_API_KEY. Never put it in browser code or a NEXT_PUBLIC_ variable. You also need a verified sending domain: see the domain setup guide.
2. Send from a server action
// app/actions.ts
"use server";
import { SendPanda } from "@sendpanda/sdk";
const panda = new SendPanda(process.env.SENDPANDA_API_KEY!);
export async function sendWelcome(userId: string, to: string) {
const email = await panda.emails.send(
{
from: "Your app <hello@your-verified-domain.com>",
to: [to],
subject: "Welcome!",
html: "<h1>Welcome to your app</h1>",
text: "Welcome to your app",
},
{ idempotencyKey: `welcome-${userId}` },
);
return { id: email.id, status: email.status };
}A queued status means the API accepted the email, not that the receiving server delivered it. The idempotency key makes a retry of the same welcome email safe; see idempotency keys.
3. Or send from a route handler
// app/api/invite/route.ts
import { SendPanda } from "@sendpanda/sdk";
export const runtime = "nodejs";
const panda = new SendPanda(process.env.SENDPANDA_API_KEY!);
export async function POST(request: Request) {
const { to, inviteId } = await request.json();
const email = await panda.emails.send(
{
from: "Your app <hello@your-verified-domain.com>",
to: [to],
subject: "You have been invited",
html: "<p>Accept your invitation.</p>",
text: "Accept your invitation.",
},
{ idempotencyKey: `invite-${inviteId}` },
);
return Response.json({ id: email.id, status: email.status });
}Protect your endpoint
A route handler that sends to any address it is given is an open mail relay. Require a signed-in user, validate the address and look the recipient up on your side rather than accepting it from the client. Every send counts against your recipient quota, and the API enforces suppressions and rate limits, but your own checks come first.
Next steps
- Quickstart for the full first-send walkthrough.
- Verify webhooks to learn when an email is delivered or bounces.
- Pricing: 1,000 emails a month free, no card.