Ethereal Email Alternative: Test Nodemailer Emails with an Address per Test
An Ethereal Email alternative for Nodemailer: send through your real provider to an address per test, then assert on subject, links and attachments in CI.

If your app sends email with Nodemailer, you have probably met Ethereal. It is the test service the Nodemailer team runs: call nodemailer.createTestAccount(), point a transport at it, and you can open each message your code sends in a preview page. It is a quick way to see that a template renders. This tutorial is for the next step, when you want an automated test to prove that the email your app sends through its real provider arrives, carries the right link and attaches the right file.
We build that test here. The app keeps its normal Nodemailer transport. Each test creates its own Mailcycle address, the app sends to it, and the test waits for the message with the TypeScript SDK and asserts on the subject, the body, the links and the attachments. It runs in node:test, in Jest and in GitHub Actions. Every snippet below was run against a live Mailcycle account on 29 November 2026.
What we say about Ethereal comes from ethereal.email and nodemailer.com, read on 29 November 2026. The pages are listed at the end.
What Ethereal Email does for Nodemailer users
Ethereal describes itself as a fake SMTP service, mostly aimed at Nodemailer and EmailEngine users. It is run by the Nodemailer team and funded by EmailEngine. Its FAQ is clear about the design: Ethereal only accepts mail for delivery and never delivers anything.
The usual Nodemailer flow has three calls. nodemailer.createTestAccount() returns a user, a password and the SMTP settings. You create a transport for smtp.ethereal.email on port 587 with STARTTLS. After sendMail(), nodemailer.getTestMessageUrl(info) gives a link of the form https://ethereal.email/message/... that shows that one message in the browser.
Ethereal’s FAQ says messages are kept for a few hours, after which they are deleted, so a preview link is for looking at a message soon after the send.
Why test Nodemailer email through your real provider
A captured message proves that your code built a message and handed it to an SMTP server. Many email bugs live after that point, in the parts a test against a capture service never touches:
- the provider rejects the message because the From domain is not verified for staging;
- a staging environment variable is missing, so the link points at
localhost; - the HTML part and the text part disagree, because one template was edited and the other was not;
- an attachment is generated empty, or with the wrong file name, on the server where the job runs;
- the token in the link is one the app does not accept.
When the test sends through the same transport as production and reads the message from a real address, each of those becomes a failing test. The flow is short: the test creates an address, your app sends to it with Nodemailer, Mailcycle receives the message and encrypts it on arrival, and the test opens it on the machine running the suite.
Ethereal and an address per test, compared
| Ethereal Email | Mailcycle | |
|---|---|---|
| Where the message goes | Captured, never delivered | Delivered to a real address |
| Sending path the test covers | Nodemailer to Ethereal’s SMTP server | Nodemailer through your own provider |
| How a test reads mail | A preview link per message | REST API, or one wait call in any of nine SDKs |
| Waiting for mail | A polling loop you write | One awaited call with a timeout |
| How long mail is kept | A few hours | Your choice per address, 1 to 90 days |
| Events | Signed message.received webhooks |
What you need
- Node.js 22.18 or later, so
node --testcan run a.tsfile directly. We used Node.js 22.23. nodemailer10.6.1 andmailcycle-sdk0.13.1. Nodemailer 10 needs Node.js 20 or later.- A Mailcycle account on the Operator plan or above, an API key and the account’s recovery phrase. The API keys reference shows where to make the key; the phrase opens the mail, which is encrypted the moment it arrives.
- Your provider’s SMTP URL for staging, the one your app already uses.
npm install nodemailer mailcycle-sdk
The app: a Nodemailer mailer that does not know it is being tested
The module below is the kind most Nodemailer apps already have. The transport comes from SMTP_URL, so production, staging and the test suite all send the same way. There is nothing test-specific in it, which is the point: the test exercises the code you ship.
// src/mailer.js
import nodemailer from 'nodemailer';
// The same transport in every environment: your provider's SMTP URL comes from the environment.
export const transporter = nodemailer.createTransport(process.env.SMTP_URL);
const APP_URL = process.env.APP_URL ?? 'https://app.example.com';
const FROM = process.env.MAIL_FROM ?? 'Acme <hello@example.com>';
export function sendWelcome(to, token) {
const link = `${APP_URL}/verify?token=${token}`;
return transporter.sendMail({
from: FROM,
to,
subject: 'Confirm your Acme account',
text: `Welcome to Acme.\n\nConfirm your email address: ${link}\n`,
html: `<p>Welcome to Acme.</p><p><a href="${link}">Confirm your email address</a></p>`,
});
}
export function sendInvoice(to, number, pdf) {
return transporter.sendMail({
from: FROM,
to,
subject: `Your Acme invoice ${number}`,
text: `Invoice ${number} is attached.\n`,
attachments: [{ filename: `invoice-${number}.pdf`, content: pdf, contentType: 'application/pdf' }],
});
}
If your app came from the Ethereal setup, this is where the change happens. Remove the branch that calls createTestAccount() when NODE_ENV is test, and let the test environment use a real SMTP_URL, such as a staging key with SendGrid, Postmark or Resend. Set MAIL_FROM to a sender your provider has verified for that environment.
Test Nodemailer emails with node:test
Here is the whole test file. It uses only node:test, node:assert and the SDK. A small helper gives every test its own address and deletes it when the test ends, through t.after().
// test/email.test.ts
import { test, before, after } from 'node:test';
import assert from 'node:assert/strict';
import { Mailcycle } from 'mailcycle-sdk';
import { sendWelcome, sendInvoice, transporter } from '../src/mailer.js';
let mc: Mailcycle;
before(async () => {
mc = await Mailcycle.withApiKey({
apiKey: process.env.MAILCYCLE_API_KEY!,
phrase: process.env.MAILCYCLE_PHRASE!,
});
});
// One address per test, removed when the test ends.
async function addressFor(t: { name: string; after: (fn: () => unknown) => void }) {
const address = await mc.addresses.create({ prefix: 'nodemailer', label: t.name, retentionDays: 1 });
t.after(() => mc.addresses.delete(address.id));
return address;
}
test('welcome email carries a working confirm link', async (t) => {
const address = await addressFor(t);
const since = new Date();
const info = await sendWelcome(address.emailAddress, 'tok_123');
assert.deepEqual(info.accepted, [address.emailAddress]);
const message = await mc.messages.waitFor({ inboxId: address.id, since, subject: 'Confirm your Acme account' });
assert.match(message.text, /Welcome to Acme/);
const links = [...message.html.matchAll(/href="([^"]+)"/g)].map((m) => new URL(m[1]));
assert.equal(links.length, 1);
assert.equal(links[0].pathname, '/verify');
assert.equal(links[0].searchParams.get('token'), 'tok_123');
});
test('invoice email attaches the PDF unchanged', async (t) => {
const address = await addressFor(t);
const since = new Date();
const pdf = Buffer.from('%PDF-1.4\n% Acme test invoice\n%%EOF\n');
await sendInvoice(address.emailAddress, 'INV-0042', pdf);
const message = await mc.messages.waitFor({ inboxId: address.id, since, subject: 'INV-0042' });
assert.equal(message.attachments.length, 1);
assert.equal(message.attachments[0].filename, 'invoice-INV-0042.pdf');
assert.equal(message.attachments[0].mimeType, 'application/pdf');
const bytes = await mc.messages.attachment(message, 0);
assert.deepEqual(Buffer.from(bytes), pdf);
});
after(() => transporter.close());
Run it with the three secrets in the environment:
node --test --test-concurrency=2 'test/**/*.test.ts'
On our run both tests passed in 8.0 seconds, from sendMail() to the last assertion:
ok 1 - welcome email carries a working confirm link
ok 2 - invoice email attaches the PDF unchanged
# tests 2
# pass 2
# fail 0
# duration_ms 8010.166292
What each assertion proves
info.accepted is Nodemailer’s own record that the provider took the message for that recipient, so a rejected sender or a wrong SMTP URL fails here, before any waiting. messages.waitFor() proves the message arrived at the address. The text match proves the plain-text part was rendered. The link checks parse every href in the HTML part, so a second, unexpected link or a wrong host fails the test. The attachment checks compare the file name, the MIME type and the exact bytes your app attached.
Why since is taken before the send
waitFor() resolves with the first matching message received from since on, and it allows five seconds for clock difference between your machine and the server. Taking since just before sendWelcome() means the test can only match the message it caused. With an address per test there is nothing older in the inbox anyway, but the habit keeps a test correct if you later reuse an address across steps, such as a sign-up email followed by a password reset.
Assert on links, HTML and plain text in Nodemailer emails
The message object from the SDK carries everything a template test needs. message.subject, message.from and message.fromName check the envelope your app set. message.text is the plain-text part. message.html is the HTML part as sent, and message.safeHtml is the same HTML with remote images, stylesheets and embeds removed, which is the one to render if you take a screenshot of the email.
For links, parse rather than search. new URL() on each href gives you the host, the path and the query, so a test can check that the token is the one the app issued and that the host is the staging app, not localhost. If a link should also appear in the text part, assert that too: message.text containing link.href catches the case where only one template was updated.
To go one step further, follow the link. If your test starts the app’s HTTP server, request the path from the email and assert on the response, which proves the token in the email is one your app accepts. The Playwright email verification tutorial does this in a browser, with OTP codes, magic links and password resets.
Test email attachments sent with Nodemailer
Nodemailer makes attachments easy to add and easy to break: a stream that ends early, a buffer that was never filled, a contentType left out so the file arrives as application/octet-stream. message.attachments lists each part with its index, filename, mimeType and size, so a test can check those without downloading anything. messages.attachment(message, index) returns the decrypted bytes as a Uint8Array.
Comparing bytes with what your app attached is the strongest check, and it is cheap for generated files. For files your app builds from data, such as a PDF invoice or a CSV export, check the first bytes (%PDF- for a PDF) and parse the content with the same library your customers’ tools would use. Inline images that the HTML shows as cid: references carry a contentId on the attachment, so a test can check that every cid: in the HTML has a matching part.
Check the sender, Reply-To and recipient
Nodemailer lets each sendMail() call set from, replyTo, cc and bcc, and those are easy to get wrong when one environment variable is missing. The SDK message has from and fromName for the sender, replyTo for where a reply would go (the Reply-To header if your app set one, otherwise From) and to for the recipient. A support email that should be answered by a team address, not the no-reply sender, is one assertion: assert.equal(message.replyTo, 'support@acme.test'). For a copy to a second person, create a second address, put it in cc, and wait on both.
Check the From name and address
The sender is where staging builds most often go wrong. A missing MAIL_FROM falls back to a default, a copied config carries another brand’s name, or a provider rewrites an unverified address. Assert the display name and the address separately, so the failure message says which one changed:
assert.equal(message.fromName, 'Acme');
assert.equal(message.from, 'hello@acme.test');
message.fromName is the display name from the From header and message.from is the bare address, with no name around it. With both checks in the suite, a build that would greet customers as the wrong company fails in CI before it ships.
Test emails sent from a background job
Many Nodemailer apps do not send inside the request. A sign-up handler adds a job to a queue such as BullMQ, and a worker process calls sendMail() a few seconds later. A capture service that the test inspects straight after the request tends to need sleeps and retries here. With waitFor() there is nothing to change: the test triggers the action, then awaits the message, and the call resolves when the worker’s email arrives, however long the queue took, up to the timeout.
Two habits help. Take since before you trigger the job, not after the request returns, so a fast worker cannot send before the window opens. And pass a timeoutMs that matches your queue: the default is 60 seconds, which covers most staging queues, while a nightly digest job tested end to end may need longer. If the job runs in a separate process in CI, start it before the suite and stop it in the global teardown, in the same way you would for the database.
Test Nodemailer with Jest
The same test in Jest needs no new ideas. mailcycle-sdk is an ES module, so run Jest with NODE_OPTIONS=--experimental-vm-modules, and keep the test in an .mjs file. Here, addresses are collected and deleted together in afterAll.
// test/email.spec.mjs
import { Mailcycle } from 'mailcycle-sdk';
import { sendWelcome, transporter } from '../src/mailer.js';
let mc;
const made = [];
beforeAll(async () => {
mc = await Mailcycle.withApiKey({ apiKey: process.env.MAILCYCLE_API_KEY, phrase: process.env.MAILCYCLE_PHRASE });
});
afterAll(async () => {
await Promise.all(made.map((id) => mc.addresses.delete(id)));
transporter.close();
});
test('welcome email links to /verify with the token', async () => {
const address = await mc.addresses.create({ prefix: 'nodemailer', retentionDays: 1 });
made.push(address.id);
const since = new Date();
await sendWelcome(address.emailAddress, 'tok_456');
const message = await mc.messages.waitFor({ inboxId: address.id, since, subject: 'Confirm your Acme account' });
const link = new URL(message.html.match(/href="([^"]+)"/)[1]);
expect(link.pathname).toBe('/verify');
expect(link.searchParams.get('token')).toBe('tok_456');
expect(message.text).toContain(link.href);
}, 90_000);
NODE_OPTIONS=--experimental-vm-modules npx jest test/email.spec.mjs
It passed in 4.3 seconds with Jest 30.5.2. The 90 second test timeout leaves room for the 60 second default of waitFor(), so a slow provider shows up as a clear “No matching mail arrived in time” error rather than a Jest timeout.
Run Nodemailer email tests in CI with GitHub Actions
In CI the suite needs three secrets: the Mailcycle API key, the recovery phrase and your provider’s SMTP URL for staging. Add them under the repository’s Actions secrets and pass them to the test step.
# .github/workflows/email-tests.yml
name: Email tests
on: [push, pull_request]
jobs:
email:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: node --test 'test/**/*.test.ts'
env:
SMTP_URL: ${{ secrets.STAGING_SMTP_URL }}
MAIL_FROM: ${{ vars.STAGING_MAIL_FROM }}
MAILCYCLE_API_KEY: ${{ secrets.MAILCYCLE_API_KEY }}
MAILCYCLE_PHRASE: ${{ secrets.MAILCYCLE_PHRASE }}
Because every test creates its own address, a matrix of Node versions, parallel jobs and two pull requests running at once never read each other’s mail. Make a separate API key for CI, so you can revoke it on its own, and keep the phrase only in secrets.
Moving a suite off Ethereal, step by step
- Find the Ethereal branch. Search for
createTestAccount,smtp.ethereal.emailandgetTestMessageUrl. Most apps have one place that swaps the transport in tests. - Use your real transport in tests. Point
SMTP_URLat your provider’s staging credentials and set a verifiedMAIL_FROM. - Replace the recipient. Wherever a test used a made-up address, create one with
mc.addresses.create()and passaddress.emailAddressto the app. - Replace the preview link with assertions. Each
console.log(getTestMessageUrl(info))becomes awaitFor()and the checks you used to do by eye: subject, link, text and attachment. - Replace polling loops. If tests read captured mail with a retry loop,
waitFor()replaces the whole loop with one awaited call. - Add the CI secrets and run the suite on every pull request.
For a preview while you write a template, open the address in the Mailcycle app: it shows the message as your customer would see it, with trackers stripped.
Plan sizing for a Nodemailer test suite
The Operator plan at $15 a month is where API keys and webhooks start. It holds 250 addresses at a time and receives 250,000 messages a month, and the rate limits reference lists address creation at twice the plan’s allowance a day, so a suite can make 500 addresses a day. A test that deletes its address frees the place straight away. Scale, at $19 a month, adds your own domains, 10 of them, so test addresses can live on a domain such as test.yourcompany.com that a staging allow-list already trusts. The plans and limits page has every figure.
Webhooks when your app reads mail too
Some Nodemailer apps also receive email: a support tool that reads replies, or a product that takes documents by email. The same account covers that side. A signed message.received webhook reaches your HTTPS endpoint with retries, and the SDK includes the signature check. Receive email with a webhook builds the receiver, and receive email in Node.js covers reading and decrypting from code.
Troubleshooting Nodemailer email tests
sendMail() fails with a 550 error
The provider or the receiving server refused the sender. Check that MAIL_FROM uses a domain your provider has verified for staging; an unverified From is the usual cause. The text of the error names the reason.
waitFor() times out
Check info.accepted first: if it holds the address, the provider took the message, so look in its activity log for that recipient. Then open the address in the Mailcycle app. A message in the inbox that the test missed points to the subject filter, which matches part of the subject, case-insensitively.
The link assertion finds no href
Print message.html once. If the template sends plain text only, parse links from message.text instead.
Jest says it cannot use import statements
Run it with NODE_OPTIONS=--experimental-vm-modules and keep the test in an .mjs file, or move the suite to node:test, which needs no configuration.
Related reading
- Test email verification in Playwright, the hub for email testing setup, and Cypress email verification
- Mailtrap alternative, Mailosaur alternative, MailSlurp alternative and testmail.app alternative
- Send email from TypeScript, when the app sends through the Mailcycle API instead
- An email address for every sign-up
- The TypeScript SDK guide, the SDK page and reading mail
Sources and dates
Every Ethereal and Nodemailer statement above was read on 29 November 2026 from these pages:
| What | Page |
|---|---|
| What Ethereal is, who provides it | https://ethereal.email/ |
| Server settings | https://ethereal.email/help |
| Delivery, retention, who runs it | https://ethereal.email/faq |
| createTestAccount, getTestMessageUrl | https://nodemailer.com/guides/testing-with-ethereal |
| Node.js version for Nodemailer 10 | https://nodemailer.com/ |
Mailcycle figures come from https://mailcycle.email/pricing, https://docs.mailcycle.email/concepts/plans-and-limits/ and https://docs.mailcycle.email/reference/rate-limits/. The code ran on Node.js 22.23.4 with nodemailer 10.6.1, mailcycle-sdk 0.13.1 and Jest 30.5.2.
FAQ
What is Ethereal Email?
Ethereal is a fake SMTP service from the Nodemailer team, funded by EmailEngine. It accepts mail from your app, shows it in a preview page and never delivers it. Nodemailer can create an account for it with nodemailer.createTestAccount(). With Mailcycle, your app sends through its real provider to a real address, and the test reads the message back with an SDK.
How do I read Nodemailer test emails from code?
With Mailcycle, a test reads mail through a REST API or an SDK: messages.waitFor() in mailcycle-sdk resolves with the next matching message, already decrypted, with its text, HTML and attachments.
How do I test Nodemailer emails in Jest?
Create a Mailcycle address in the test, call the function in your app that sends with Nodemailer, then call messages.waitFor() with the address id and the subject. Assert on message.text, message.html and message.attachments with expect(). Run Jest with NODE_OPTIONS=--experimental-vm-modules, since mailcycle-sdk is an ES module.
Can I test Nodemailer emails with node:test instead of Jest?
Yes. node:test ships with Node.js, and Node.js 22.18 and later run a .ts test file directly. Each test creates its own address, registers t.after() to delete it, and awaits messages.waitFor(). The tutorial above runs two such tests in 8 seconds.
Do I have to change my Nodemailer transport to use Mailcycle?
No. Your transport keeps pointing at your normal provider, so staging sends exactly as production does. The only change is the recipient: the test passes the address it created to your app instead of a made-up one.
How do I check an email attachment in a Node.js test?
Read message.attachments for the file name, type and size, then fetch the bytes with messages.attachment(message, index) and compare them with what your app attached. The tutorial checks that a PDF invoice arrives byte for byte.
How do I run Nodemailer email tests in GitHub Actions?
Store MAILCYCLE_API_KEY, MAILCYCLE_PHRASE and your provider's SMTP URL as repository secrets, pass them to the test step as environment variables, and run node --test. Each test makes its own address, so parallel jobs never read each other's mail.
Which Mailcycle plan do I need for Nodemailer tests?
Operator, at $15 a month, is the first plan with API keys and webhooks, and it holds 250 addresses at a time with 250,000 messages received a month. Scale, at $19 a month, adds 10 of your own domains for test addresses.
How long does Mailcycle keep test emails?
You choose per address, from 1 to 90 days, and the default is 7. Tests in this tutorial use retentionDays 1 and delete each address when the test ends.
Receive email in code
- AgentMail Alternative for AI Agent Inboxes (AgentMail alternative)
- CloudMailin Alternative: Inbound Email to Rails With an Address per API Call (CloudMailin alternative)
- Mailgun Inbound Routes Alternative: Route Mail by Address, Not Regex (Mailgun Routes alternative)
- Mailosaur Alternative for Email Testing and Test Inboxes (Mailosaur alternative)
- Mailparser and Parseur Alternative: Incoming Email as JSON on a Webhook (Mailparser and Parseur alternative)
- MailSlurp Alternative for Email Testing and Test Inboxes (MailSlurp alternative)
- Mailtrap Alternative for Email Testing and Test Inboxes (Mailtrap alternative)
- Postmark Inbound Alternative: Addresses by API, Signed Webhooks (Postmark inbound alternative)
- Resend Inbound Alternative: An Address per API Call, Signed Events (Resend inbound alternative)
- SendGrid Inbound Parse Alternative: Inbound Email by API Call (SendGrid Inbound Parse alternative)
- Testmail.app Alternative for Email Testing and Test Inboxes (Testmail.app alternative)
- Test Email Flows on Real Devices with Appium: Read Sign-Up Codes in Python (Appium)
- How to Give a Browser Use Agent an Email Address and Let It Read Its Own Verification Code (Browser Use sign-ups)
- How to Receive Email in C#: Read the Inbox, Save Attachments and Get New Mail Pushed (C# / .NET)
- How to Test Email Verification in Cypress: Receive Sign-Up Codes with cy.task (Cypress)
- Golang Receive Email: How to Receive and Read Email in Go (Go)
- How to Read Email in Java: Read the Inbox, Save Attachments and Receive Mail in Spring Boot (Java)
- How to Receive Email in PHP with an Email API: Read the Inbox, Save Attachments and Handle Webhooks (PHP / Laravel)
- How to Receive Email in Python: Read the Inbox, Save Attachments and Get New Mail Pushed (Python)
- Receive Email in Ruby and Rails: Read the Inbox, Save Attachments and Handle Webhooks (Ruby)
- How to Receive Email in Rust: Read the Inbox, Save Attachments and Handle Webhooks in Axum (Rust)
- Add Inbound Email to Your SaaS: Support Intake and Reply-by-Email (SaaS support)
- How to Verify Email in Selenium Tests: Read Sign-Up Codes with Python and pytest (Selenium)
- How to Handle Email Verification in a Stagehand Browser Agent: Create an Address, Wait for the Code, Delete It (Stagehand sign-ups)
- How to Receive Email in Swift: Read the Inbox, Save Attachments and Handle Vapor Webhooks (Swift)
- Test Accounts for Security Testing: a Separate Email Address per Program (Test accounts for security testing)
- How to Automate Email Verification in Tests with Playwright: OTP Codes, Magic Links and Password Resets (Testing email verification)
- How to Receive Email in Node.js: Read the Inbox, Save Attachments and Handle Webhooks (TypeScript / Node.js)
- How to Receive Email with a Webhook: Inbound Email to Your HTTP Endpoint (Webhooks)