Working test, run November 25, 2026
Temp mail for Cypress: test signups with a disposable inbox
By Waqar Habib Khan | Published 2026-11-25 | The spec below was executed locally before this page shipped
Quick answer
How do I use temp mail in a Cypress test?
- One inbox per test run: runs never share state and never flake on each other.
- One long-poll instead of a polling loop: the wait call counts as one API call.
- Needs a Premium, Developer, or Business API key: the Free plan returns 402.
How the test works
1. Create a fresh inbox. The test POSTs to /api/v1/inbox with cy.request and gets a random address back, plus its expiry. It asserts the address matches the expected shape and expires in the future, so a broken API response fails fast instead of failing later at the form.
2. Prove the inbox starts empty. It calls the OTP endpoint before any mail exists. The endpoint answers 200 with message: null, which tells the test that empty inboxes are normal and distinct from a missing inbox (404).
3. Sign up. Cypress opens the signup URL, types the disposable address into the email field, and submits. The URL and the selectors all come from --expose values, so the same spec runs against staging and production.
4. Wait, then read the code. The wait endpoint holds the request for up to 55 seconds until the verification mail lands. Then the OTP endpoint returns the code the server extracted from the message, so the test never parses an email body itself.
5. Enter the code and assert. The test types the code, submits, and waits for the success text. The inbox is never reused: the next run creates its own.
The full spec
Save it as temp-mail-cypress.cy.ts, or download the same file here: temp-mail-cypress.cy.ts. It was executed locally on November 25, 2026 with Cypress 16.3.0 against a stub that mirrors the real endpoint paths, status codes, and JSON shapes, with a fake signup page that sends a real verification code through the same flow; the live endpoints were probed the same day and return the documented 401 responses without a key. It has not been run end to end against the live API with a paid key in this environment, because no paid-plan key exists here: the first run with a real key is yours, and the test is written to make that run the same as the local one. The spec needs Cypress 15.10 or later: that version added cy.env() and Cypress.expose(), which replaced the Cypress.env() call removed in Cypress 16.
temp-mail-cypress.cy.ts
// Ambient declarations for the Cypress runner globals. This file runs
// under Cypress, where `cy`, `Cypress`, `describe`, `it`, `before`,
// `beforeEach` and `expect` exist; this repo does not install Cypress
// types, so the globals are declared here to keep `tsc` quiet.
declare const cy: any;
declare const Cypress: any;
declare const describe: any;
declare const it: any;
declare const before: any;
declare const beforeEach: any;
declare const expect: any;
// Public settings: safe to read synchronously from the browser context.
const API_BASE = (
Cypress.expose("TEMPIFY_API_BASE") ?? "https://tempify.org/api/v1"
).replace(/\/$/, "");
const SIGNUP_URL = Cypress.expose("SIGNUP_URL") ?? "";
const EMAIL_SELECTOR =
Cypress.expose("SIGNUP_EMAIL_SELECTOR") ?? 'input[type="email"]';
const SUBMIT_SELECTOR =
Cypress.expose("SIGNUP_SUBMIT_SELECTOR") ?? 'button[type="submit"]';
const CODE_SELECTOR =
Cypress.expose("SIGNUP_CODE_SELECTOR") ?? 'input[name="code"]';
const SUCCESS_TEXT = Cypress.expose("SIGNUP_SUCCESS_TEXT") ?? "Welcome";
// The API key is sensitive: it is read asynchronously with cy.env() and
// never stored in a global the page under test can see.
let API_KEY = "";
function apiHeaders() {
return { "x-api-key": API_KEY };
}
describe("temp mail signup", () => {
before(() => {
cy.env(["TEMPIFY_API_KEY"]).then(({ TEMPIFY_API_KEY }) => {
API_KEY = TEMPIFY_API_KEY ?? "";
});
});
beforeEach(function () {
if (!API_KEY) {
this.skip();
}
});
it("create inbox, sign up, wait for code, assert", () => {
// 1. Create a fresh inbox for this test run only.
cy.request({
method: "POST",
url: `${API_BASE}/inbox`,
headers: apiHeaders(),
body: {},
}).then((created) => {
expect(created.status, "create inbox").to.eq(201);
const address: string = created.body.inbox.address;
expect(address).to.match(/^[a-z0-9._-]+@[a-z0-9.-]+$/);
expect(new Date(created.body.inbox.expires_at).getTime()).to.be.greaterThan(
Date.now(),
);
// The inbox starts empty: the OTP endpoint answers 200 with no message.
cy.request({
method: "GET",
url: `${API_BASE}/inbox/${encodeURIComponent(address)}/otp`,
headers: apiHeaders(),
}).then((empty) => {
expect(empty.status, "otp on empty inbox").to.eq(200);
expect(empty.body.message).to.eq(null);
});
if (!SIGNUP_URL) {
// No app under test configured: prove the wait primitive works and stop.
// A 10 second wait on an inbox nobody mails to times out cleanly.
// The wait can hold the request up to the timeout, so raise Cypress's
// response timeout above it.
cy.request({
method: "GET",
url: `${API_BASE}/inbox/${encodeURIComponent(address)}/wait?timeout=10`,
headers: apiHeaders(),
timeout: 30000,
}).then((waited) => {
expect(waited.status, "wait for mail").to.eq(200);
expect(waited.body.timed_out).to.eq(true);
expect(waited.body.messages).to.deep.eq([]);
});
return;
}
// 2. Sign up with the disposable address.
cy.visit(SIGNUP_URL);
cy.get(EMAIL_SELECTOR).first().type(address);
cy.get(SUBMIT_SELECTOR).first().click();
// 3. Wait for the verification mail (long-poll: one API call, up to 55s).
// The wait can hold the request for the full 55 seconds, so raise
// Cypress's response timeout above it.
cy.request({
method: "GET",
url: `${API_BASE}/inbox/${encodeURIComponent(address)}/wait?timeout=55`,
headers: apiHeaders(),
timeout: 70000,
}).then((arrived) => {
expect(arrived.status, "wait for verification mail").to.eq(200);
expect(arrived.body.timed_out, "verification mail arrived").to.eq(false);
expect(arrived.body.messages.length).to.be.greaterThan(0);
// 4. Read the code the server extracted from the latest message.
cy.request({
method: "GET",
url: `${API_BASE}/inbox/${encodeURIComponent(address)}/otp`,
headers: apiHeaders(),
}).then((otp) => {
expect(otp.status, "read otp").to.eq(200);
expect(otp.body.otp, "verification code extracted").to.match(
/^\d{4,8}$/,
);
// 5. Enter the code and assert the signup completed.
cy.get(CODE_SELECTOR).first().type(otp.body.otp);
cy.get(`${SUBMIT_SELECTOR}:visible`).first().click();
cy.contains(SUCCESS_TEXT).should("be.visible");
});
});
});
});
});Run it
The test skips itself with a clear message when TEMPIFY_API_KEY is not set, instead of failing with a confusing 401. Without SIGNUP_URL it runs the inbox half of the flow only: create, prove empty, and prove the wait times out cleanly on an inbox nobody mails to. That is the fastest way to check your key and the API wiring before pointing the test at a real signup form. The key travels through --env and is read with cy.env(), so it is never serialised into the browser context; the public settings travel through --expose and are read with Cypress.expose().
Run locally
npx cypress run --spec temp-mail-cypress.cy.ts \
--env TEMPIFY_API_KEY=your_key \
--expose SIGNUP_URL=https://example.com/signup
# Against staging, with custom selectors:
npx cypress run --spec temp-mail-cypress.cy.ts \
--env TEMPIFY_API_KEY=your_key \
--expose SIGNUP_URL=https://staging.example.com/signup,SIGNUP_SUCCESS_TEXT="Check your inbox"Run it in CI (GitHub Actions)
Store the key as a repository secret called TEMPIFY_API_KEY and the signup URL as a variable called SIGNUP_URL. Never commit a key to the repository: a key in git history is a key anyone can use against your monthly allowance.
GitHub Actions
name: signup tests
on:
push:
branches: [main]
jobs:
signup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx cypress run --spec temp-mail-cypress.cy.ts
--env TEMPIFY_API_KEY=${{ secrets.TEMPIFY_API_KEY }}
--expose SIGNUP_URL=${{ vars.SIGNUP_URL }}The API calls behind the test
Three inbox endpoints do all the work. The full reference, with error codes, rate limit headers, and the OpenAPI spec, is on the temporary email API page.
| Call | What the test uses it for | Cost |
|---|---|---|
| POST /api/v1/inbox | Create one inbox per run | 1 call |
| GET /api/v1/inbox/{address}/wait | Hold until the verification mail arrives (up to 55s) | 1 call, however long it holds |
| GET /api/v1/inbox/{address}/otp | Read the server-extracted code | 1 call |
A full run costs 3 to 4 API calls, so the Premium allowance of 1,000 calls a month covers roughly 250 signup tests. If your suite runs hotter than that, Business at $49 a month includes 50,000 calls. The test asserts on every API status, so a 402 (Free plan), 401 (bad key), or 429 (allowance exhausted) fails loudly at the step that caused it instead of surfacing later as a missing code.
Keep going
Temp mail for Cypress questions, answered
The questions QA engineers ask before adding this test to a suite.
Can I use temp mail in a Cypress test?
Yes. The test on this page creates a fresh Tempify inbox through the API with cy.request, fills the signup form with that address, waits for the verification mail with the API long-poll endpoint, reads the extracted code, and asserts the signup completed. Every test run gets its own inbox, so runs never share state.
Do I need a paid plan to use temp mail in Cypress?
Yes. The test calls the Tempify API, and API access starts on Premium at $4.99 a month (1,000 calls a month). The Free plan returns 402 on every API call, so the test skips itself when no key is set and fails with 402 on a Free-plan key. The Developer plan at $19 a month with 10,000 calls a month is coming soon; Business at $49 a month includes 50,000 calls.
How does the test wait for the verification email?
It calls GET /api/v1/inbox/{address}/wait?timeout=55 with cy.request, which holds the request until a message arrives or 55 seconds elapse. One wait counts as one API call however long it holds, so the test does not poll in a loop and does not burn the monthly allowance. The wait can hold the request for the full 55 seconds, so the request sets a 70 second response timeout, above Cypress's 30 second default. On timeout the response is 200 with timed_out true, and the test fails with a clear message instead of hanging.
How do I pass the API key to the test?
The key is a sensitive value, so Cypress 16 reads it with cy.env(), not the removed Cypress.env(). Pass it with --env TEMPIFY_API_KEY=your_key on the command line, or set the CYPRESS_TEMPIFY_API_KEY environment variable. The public settings (signup URL, selectors, success text) are passed with --expose and read with Cypress.expose(). On Cypress 15.9 or older, use Cypress.env() for everything instead; the cy.env() and Cypress.expose() calls need Cypress 15.10 or later.
How do I run this test in CI?
Save the spec file, add your API key as a repository secret called TEMPIFY_API_KEY, and run npx cypress run with the key passed through --env. The CI snippet on this page shows the GitHub Actions job. The test reads the signup URL and selectors from --expose values, so the same spec runs against staging and production by changing variables, not code.
What if the verification email is slow?
The wait endpoint holds up to 55 seconds per call, which covers most verification mail. If your mailer is slower than that, call wait again with the since parameter set to the first call's start time: only messages after that timestamp are returned, so the second wait does not re-read old mail. Do not generate a new inbox and restart the signup: a new address restarts the sender's delivery clock.
Does the test work with Playwright or Selenium too?
The API calls are plain HTTP, so the same flow works in any framework: create the inbox with POST /api/v1/inbox, submit the form, wait with GET /api/v1/inbox/{address}/wait, and read the code with GET /api/v1/inbox/{address}/otp. Only the browser-driving code changes. The API reference at tempify.org/developers/temporary-email-api documents every call the test uses.