Next.js integration

Send transactional emails from Next.js — App Router and Pages Router

Fire an event from a Server Action or API route. else.events routes it to the right template and delivers through your email provider. No email library in your Next.js bundle.

Email libraries in Next.js create friction

Email libraries increase bundle size

Adding Nodemailer, React Email or an SDK to your Next.js project increases build size and can cause edge runtime incompatibilities.

Templates live in your repo

React Email components and HTML strings commit to your repository — every copy change means a PR and a deploy.

Server Actions complicate email calls

Calling email libraries inside Server Actions mixes product logic with email delivery in ways that are hard to test and hard to separate.

Inconsistent email behavior across environments

Email configuration differs between local, preview and production — easy to break, hard to debug.

One HTTP call from any Next.js server context

Works in App Router Server Actions

Call the else.events API from any async Server Action. No client-side exposure of API keys.

Works in API routes (Pages and App Router)

Use from route.ts handlers or pages/api endpoints — same fetch pattern, same event schema.

No library in your bundle

No email SDK import. Just fetch and a JSON payload. Edge-runtime compatible.

Consistent behavior across environments

Set ELSE_EVENTS_API_KEY per environment. Email behavior is controlled in else.events — not in your Next.js config.

// Next.js App Router — Server Action

Fire an event from a Server Action.

// app/actions/billing.ts
'use server';

export async function handleTrialExpiry(userId: string) {
  const user = await db.users.findUnique({ where: { id: userId } });

  await fetch('https://app.else.events/api/events', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.ELSE_EVENTS_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      type: 'trial.expired',
      user: { email: user.email, name: user.name },
      data: { plan: user.plan, upgrade_url: 'https://app.example.com/pricing' },
    }),
  });
}

Server Actions, route handlers or middleware — the else.events API works from any Next.js server context. No email library in your component tree.

Frequently asked questions

Does this work with the Edge Runtime?
Yes. The else.events integration is a plain fetch call with no Node.js-specific dependencies. It works in edge middleware and edge API routes.
How do I secure the API key in Next.js?
Use an environment variable prefixed without NEXT_PUBLIC_ so it is server-only. Never expose it client-side.
Can I call this from a Client Component?
No — and you should not. Keep email sends in Server Actions or route handlers to avoid exposing your API key.
What about preview deployments?
Set a different ELSE_EVENTS_API_KEY in your preview environment or use a test workspace in else.events to avoid sending real emails from preview branches.

Email events from Next.js — without the email library.

One environment variable. One fetch call. Templates managed outside your repo.

  • No email SDK in your Next.js bundle
  • Edge-runtime compatible
  • Templates editable without redeploys