Send Email with Next.js
Send transactional email from Next.js App Router with the Reloop Node.js SDK — Server Actions and Route Handlers, install, env setup, and full examples.
Installation
npm install reloop-email
Setup environment variables
Add your Reloop API key to .env.local (server-only — do not use NEXT_PUBLIC_):
RELOOP_API_KEY=rl_your_api_key_here
Shared client
// lib/reloop.ts
import { Reloop } from "reloop-email";
export const reloop = new Reloop({
apiKey: process.env.RELOOP_API_KEY!,
});
Route Handler
// app/api/send-email/route.ts
import { NextResponse } from "next/server";
import { reloop } from "@/lib/reloop";
export async function POST(request: Request) {
try {
const { to, subject, html, text } = await request.json();
const { response, emailError } = await reloop.mail.send({
from: "Acme <onboarding@mail.yourdomain.com>",
to,
subject: subject ?? "Hello from Next.js",
html: html ?? "<p>Congrats on sending your first email via Reloop!</p>",
text: text ?? "Congrats on sending your first email via Reloop!",
});
if (emailError) {
return NextResponse.json({ error: emailError }, { status: 502 });
}
return NextResponse.json(response);
} catch (error) {
return NextResponse.json({ error }, { status: 500 });
}
}
Server Action
// app/actions/send-email.ts
"use server";
import { reloop } from "@/lib/reloop";
export async function sendWelcomeEmail(email: string) {
const { response, emailError } = await reloop.mail.send({
from: "Acme <onboarding@mail.yourdomain.com>",
to: email,
subject: "Welcome",
html: "<p>Thanks for signing up.</p>",
text: "Thanks for signing up.",
});
if (emailError) {
return { ok: false as const, error: "Failed to send" };
}
return { ok: true as const, messageId: response?.messageId };
}
Full guide
For forms, auth, Edge runtime, Vercel deploy, and a full comparison of Server Actions vs Route Handlers, see the blog post: How to Send Email in Next.js App Router.
Was this page helpful?
- Need help? Contact Support.
- Chat with Reloop developers on Discord.
- Check out our changelog.
- Questions? Contact Sales.
- LLM? Read llms.txt.