# Email OTP

To fetch and check an emailed OTP in a Cypress test of your own app, Humanless gives the test a disposable inbox and returns the code already extracted. Call it from Node through `cy.task`: create an inbox, type its address, record `Date.now()`, submit, then wait for the code with `waitForCode` and type it. The code comes back as a string, so leading zeros survive, and messages without a code are skipped. To validate the OTP itself, assert its length or format before typing it, and test a wrong or expired code too, which needs no email at all.

```ts otp.cy.ts
// Tasks (createInbox, waitForCode, waitForLink): see /answers/how-to-read-emails-in-cypress
cy.task("createInbox").then(({ identity_id, email }: any) => {
  cy.visit("/login");
  cy.get("input[name=email]").type(email);
  cy.then(() => {
    const since = Date.now();
    cy.contains("button", "Send code").click();
    cy.task("waitForCode", { id: identity_id, since }).then((code) => {
      expect(String(code)).to.match(/^\d{6}$/);
      cy.get("input[name=code]").type(String(code));
    });
  });
});
```

## Other options

- **Mailpit** with `cy.request` against its REST API, for local and CI runs.
- **Read the OTP from your test database** in a `cy.task`, if the test isn't about email delivery.
- **cypress-mailosaur** or MailSlurp, hosted alternatives with Cypress plugins.

> **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/email-otp

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