> ## Documentation Index
> Fetch the complete documentation index at: https://docs.devhelm.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Waiting for an email in a test

> Block until mail arrives at an address, using the SDK, CLI, or REST

Start the wait, then trigger the product to send mail to that address. The call returns the captured message, or fails when nothing arrives in time.

Set `DEVHELM_WORKSPACE_ID` to the workspace that owns the domain. The SDK sends it for you when that variable is set. REST calls send it as `x-phelm-workspace-id`.

## SDK

`to` is the full address. `timeoutMs` / `timeout_ms` is milliseconds (60 seconds below). The maximum is 120000.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const message = await client.email.wait({
    to: "signup@your-domain.example",
    timeoutMs: 60_000,
  });
  console.log(message.subject);
  ```

  ```python Python theme={null}
  message = client.email.wait(
      to="signup@your-domain.example",
      timeout_ms=60_000,
  )
  print(message.subject)
  ```
</CodeGroup>

The SDK starts the lookback at the moment you call `wait`. Mail that arrived earlier is not returned. Pass `receivedAfter` / `received_after` when the message may already be stored.

When you already split the address, `waitLocalPart` / `wait_local_part` posts to `/api/v1/email/{localpart}/wait` and sends `domain` in the body.

## CLI

```bash theme={null}
devhelm email wait --to signup@your-domain.example --timeout-ms 60000
```

The table includes an OTP column. JSON output is the message.

## REST

```bash theme={null}
curl -X POST "https://api.devhelm.io/api/v1/email/wait" \
  -H "Authorization: Bearer $DEVHELM_API_TOKEN" \
  -H "x-phelm-workspace-id: $DEVHELM_WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{"to":"signup@your-domain.example","timeoutMs":60000}'
```

Omit `receivedAfter` and the API looks back 60 seconds. A wait that finds nothing returns HTTP 408 with code `WAIT_TIMEOUT`.

## Next steps

<CardGroup cols={2}>
  <Card title="OTPs and links" icon="key" href="/testing/email/otp-and-links">
    Read the code from the message you just waited for.
  </Card>

  <Card title="How capture works" icon="envelope" href="/testing/email/overview">
    Domains, what is stored, and plan retention.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.