Node.js

A Nodemailer transport pointed at a sandbox, and every sendMail lands there.

Before you start

  • Node.js 18 or later

1Install Nodemailer

npm install nodemailer

2Create the transport

mailer.js
import nodemailer from 'nodemailer';

export const mailer = nodemailer.createTransport({
  host: 'smtp.mailclutch.com',
  port: 587,
  secure: false, // STARTTLS is negotiated after connecting
  auth: {
    user: 'mc_0000000000000000',
    pass: 'pw_0000000000000000',
  },
});

secure: false on port 587 is not a downgrade: the connection starts in the clear and is upgraded by STARTTLS. secure: true belongs to port 465.

3Send a test message

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

await mailer.verify() checks the connection and the credentials without sending anything.

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

  • The process exits before the mail leaves

    In a short script, await sendMail — an unawaited promise dies with the process and the message never goes out.

  • Keep the pair in the environment

    Read user and pass from process.env in anything you commit. They are inlined here so the snippet runs as pasted.

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