Next.js

Send from a Route Handler or a Server Action — the sandbox catches it like any other SMTP client.

Before you start

  • Next.js 13.4 or later (App Router)
  • Nodemailer

1Install Nodemailer

npm install nodemailer

2Put the credentials in the environment

.env.local
# .env.local
SMTP_HOST=smtp.mailclutch.com
SMTP_PORT=587
SMTP_USER=mc_0000000000000000
SMTP_PASSWORD=pw_0000000000000000

No NEXT_PUBLIC_ prefix: these must stay on the server. A prefixed variable is inlined into the client bundle and shipped to every visitor.

3Send from a Route Handler

app/api/send/route.ts
// app/api/send/route.ts
import nodemailer from 'nodemailer';

export async function POST() {
  const transporter = nodemailer.createTransport({
    host: process.env.SMTP_HOST,
    port: Number(process.env.SMTP_PORT),
    auth: {
      user: process.env.SMTP_USER,
      pass: process.env.SMTP_PASSWORD,
    },
  });

  await transporter.sendMail({
    from: 'staging@example.com',
    to: 'anyone@example.com',
    subject: 'Sandbox check',
    html: '<h1>Hello from Next.js</h1>',
  });

  return Response.json({ sent: true });
}

Watch it land

Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.

Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.

Awaiting your email

Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.

What usually goes wrong

  • Not from the Edge runtime

    Nodemailer opens a TCP socket, which the Edge runtime does not have. Leave the route on the Node.js runtime, which is the default.

  • Server Actions work the same way

    A 'use server' function can create the transport and send directly — same code, no route needed.

Official documentationNodemailer — SMTP transport (opens in a new tab)