Node.js

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

Prerequisites

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

  • Unawaited sendMail

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

  • Connection timeout

    A timeout rather than an error usually means port 587 is blocked on your network. Switch port to 2525, or to 465 with secure: true.

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