Next.js

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

Prerequisites

  • 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 sandbox with an account and it stays.

Awaiting your email

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

Go further

  • 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.

  • Serverless and unawaited sends

    On Vercel and other serverless hosts the function is frozen as soon as the response is sent. A sendMail that is not awaited before return never reaches the sandbox.

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