Sign inGet Started

Node.js SDK

Send email with Next.js

Use Parcel Wing from App Router route handlers and server actions without exposing API keys to the browser.

Install the SDK

The official SDK is published as @parcelwing/node.

Terminal

npm install @parcelwing/node

Route handler

Create a server-only route handler for contact forms, welcome emails, invites, and transactional messages.

app/api/send-welcome/route.ts

import { ParcelWing } from "@parcelwing/node";
import { NextResponse } from "next/server";
 
const parcelWing = new ParcelWing({ apiKey: process.env.PARCEL_WING_API_KEY! });
 
export async function POST(request: Request) {
const { email, name } = await request.json();
 
const [message] = await parcelWing.emails.send({
from: "Acme <[email protected]>",
to: email,
template_alias: "welcome_email",
template_params: { first_name: name ?? "friend" },
});
 
return NextResponse.json({ id: message?.id });
}

Server action

Server actions work well for forms that send an email after validation and persistence.

app/invite/actions.ts

"use server";
 
import { parcelWing } from "@/lib/parcelwing";
 
export async function sendInviteEmail(formData: FormData) {
const email = String(formData.get("email") ?? "");
 
await parcelWing.emails.send({
from: "Acme <[email protected]>",
to: email,
subject: "You have been invited",
text: "Create your account to join the workspace.",
});
}

Production notes

  • Keep PARCEL_WING_API_KEY in server-only environment variables.
  • Validate recipient addresses and public form input before sending.
  • Use saved templates for onboarding, invites, receipts, and other repeatable lifecycle email.