# How to read Gmail emails with Playwright

If you only need Gmail as a place for test emails to land, Humanless is simpler: each test gets its own disposable address, and `waitForCode` or `waitForLink` returns the parsed code or link over one HTTP call, with no OAuth client, refresh token or Gmail UI involved. If the test really has to use Gmail, don't drive the Gmail web UI with Playwright, because it is slow, fragile and triggers Google's bot checks. Use the Gmail API instead: search with `users.messages.list` and a query like `to:qa+run42@yourdomain.com newer_than:1h`, fetch the message with `users.messages.get`, and base64url-decode the body.

```ts humanless-instead-of-gmail.ts
const inbox = await hl.createIdentity({ channels: ["email"] });
await page.getByLabel("Email").fill(inbox.email!);
const since = Date.now();
await page.getByRole("button", { name: "Send code" }).click();
const msg = await hl.waitForMessage({ identityId: inbox.identity_id, since, timeout: 25 });
console.log(msg.type, msg.code, msg.url, msg.subject);
```

## Other options

- **Gmail API with plus-addressing**: one Google Workspace mailbox, a unique `+tag` per test, and `googleapis` in Node. Expect to maintain OAuth credentials in CI and to poll.
- **IMAP** with an app password, for example with the `imapflow` package. Same polling, fewer Google Cloud settings.
- **Mailpit** if the environment's email can be sent to a local SMTP server instead.

> **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 in Playwright](/guides/playwright-email-otp) · [All answers](/answers/)

Last updated 2026-12-04

Canonical: https://usehumanless.com/answers/how-to-read-gmail-emails-with-playwright

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