# How to read emails in Cypress

Humanless lets Cypress read email from Node through `cy.task`, since Cypress can't read a mailbox itself. Register three tasks in `cypress.config.ts`: one creates a disposable inbox, one waits for the next message and returns its parsed code or link, and one deletes the inbox. Your spec types the address into the form, calls the wait task, and uses the result. Keep the wait under Cypress's `taskTimeout` (60 seconds by default). Each message also carries `subject`, `sender` and a 280-character `raw_snippet` if you need to assert on the email's content.

```ts cypress.config.ts
import { defineConfig } from "cypress";
import { Humanless } from "humanless"; // npm i -D humanless

const hl = new Humanless({ apiKey: process.env.HUMANLESS_API_KEY! });
type Wait = { id: string; since: number };

export default defineConfig({
  e2e: {
    setupNodeEvents(on) {
      on("task", {
        createInbox: () => hl.createIdentity({ channels: ["email"] }),
        waitForEmail: ({ id, since }: Wait) => hl.waitForMessage({ identityId: id, since, timeout: 50 }),
        waitForCode: ({ id, since }: Wait) => hl.waitForCode({ identityId: id, since, timeout: 50 }).then((m) => m.code),
        waitForLink: ({ id, since }: Wait) => hl.waitForLink({ identityId: id, since, timeout: 50 }).then((m) => m.url),
        deleteInbox: (id: string) => hl.deleteIdentity(id),
      });
    },
  },
});
```

## Other options

- **Mailpit** plus `cy.request("GET", "http://localhost:8025/api/v1/search?query=...")`, retried until the message exists.
- **cypress-mailosaur** or the MailSlurp client: hosted inboxes with Cypress plugins.
- **IMAP or the Gmail API** inside a `cy.task`, if the mail must go to a real mailbox.

> **Use policy:** Only for apps you own or are authorized to test. See the [Terms](/terms).

More: [How to test email OTP and verification codes (the approach applies to Cypress)](/guides/playwright-email-otp) · [All answers](/answers/)

Last updated 2026-12-04

Canonical: https://usehumanless.com/answers/how-to-read-emails-in-cypress

---
More: https://usehumanless.com/llms.txt
