Temp Mail API for Cypress
Cypress email tests become reliable when every spec owns a real, temporary inbox. TempMailGrab provides that inbox by API and returns parsed OTP codes without making your test parse email bodies.
Your Temporary Email Address
Waiting for mail...
- No signup
- 24-hour inbox
- OTP auto-detect
- Zero tracking
- Android · Chrome · Firefox
- Developer API
Where Cypress email tests usually fail
Email verification touches more systems than the browser: app code, background jobs, SMTP routing, template rendering, link generation, and mailbox delivery. A fake inbox can miss those failures, while a shared real inbox creates test collisions.
The safer pattern is one temporary inbox per Cypress spec or per test. TempMailGrab keeps the mailbox private to your API key and returns structured fields for OTP codes and verification links.
Cypress command pattern
// cypress/support/commands.js
Cypress.Commands.add("createTempInbox", () => {
return cy.request({
method: "POST",
url: "https://tempmailgrab.com/api/v1/inbox",
headers: { Authorization: "Bearer " + Cypress.env("TMG_API_KEY") },
}).then((res) => res.body);
});
Cypress.Commands.add("waitForTempMailOtp", (inboxId) => {
const poll = (attempt = 0) => {
expect(attempt, "OTP polling attempts").to.be.lessThan(30);
return cy.request({
url: "https://tempmailgrab.com/api/v1/inbox/" + inboxId + "/messages",
headers: { Authorization: "Bearer " + Cypress.env("TMG_API_KEY") },
}).then((res) => {
const otp = res.body.messages?.find((m) => m.extracted_otp)?.extracted_otp;
if (otp) return otp;
return cy.wait(2000).then(() => poll(attempt + 1));
});
};
return poll();
});
Example spec
it("verifies a signup code", () => {
cy.createTempInbox().then((inbox) => {
cy.visit("/signup");
cy.findByLabelText("Email").type(inbox.address);
cy.findByRole("button", { name: "Create account" }).click();
cy.waitForTempMailOtp(inbox.id).then((otp) => {
cy.findByLabelText("Verification code").type(otp);
cy.findByRole("button", { name: "Verify" }).click();
cy.contains("Account verified").should("be.visible");
});
});
});
CI recommendations
- Store
TMG_API_KEYas a CI secret, never in the repo. - Create a unique inbox for each parallel Cypress worker.
- Use a 30-60 second polling window for real email systems.
- Delete inboxes in cleanup when a spec creates unusually large attachments.
Useful companion links
- Full API documentation
- OpenAPI specification
- Email testing API overview
- Long-form Cypress tutorial
- TempMailGrab package on npm
Last verified: . Cypress and endpoint examples may change; check the API docs before copying into production CI.
Automate inboxes with the API
Prefer to script it? Generate disposable inboxes and read auto-parsed OTPs & verification links programmatically — built for QA, test automation, and bots. The same private inboxes, over a clean REST API.
# 1. Create a private inbox
curl -X POST https://tempmailgrab.com/api/v1/inbox \
-H "Authorization: Bearer $TMG_API_KEY"
# → { "id": "inb_…", "address": "a1b2c3d4e5f6@tempmailgrab.com" }
# 2. Poll for mail — the OTP + verification links are auto-extracted
curl https://tempmailgrab.com/api/v1/inbox/$ID/messages \
-H "Authorization: Bearer $TMG_API_KEY"
# → { "messages": [{ "extracted_otp": "123456", "extracted_links": [ … ] }] }Related guides
Frequently Asked Questions
Can Cypress verify real emails without using a permanent test inbox?
Yes. Create a temporary inbox through the TempMailGrab API, submit that address in the Cypress test, and poll the inbox-specific messages endpoint for the verification email.
How do I avoid flaky OTP tests in Cypress?
Use one inbox per test or worker, poll with a clear timeout, and read the extracted_otp field instead of parsing message text inside the test.
Where should the API key live?
Keep the TempMailGrab API key in Cypress environment variables or CI secrets. Do not commit it to cypress.config.js or source control.