> ## 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.

# Extracting OTPs and links

> Read one-time codes and links from a captured message with the SDK, CLI, or REST

A captured message already includes the codes and links DevHelm found. `otp[].value` is the code. `otp[].source` is `text` or `html` — the same digits often appear once per part, so tests use the first value. `links[].href` is the URL, and `links[].text` is the visible text when the message had any.

## From the message you waited for

<CodeGroup>
  ```typescript TypeScript theme={null}
  const message = await client.email.wait({
    to: "signup@your-domain.example",
    timeoutMs: 60_000,
  });
  const code = message.otp?.[0]?.value;
  const href = message.links?.[0]?.href;
  ```

  ```python Python theme={null}
  message = client.email.wait(
      to="signup@your-domain.example",
      timeout_ms=60_000,
  )
  code = message.otp[0].value if message.otp else None
  href = message.links[0].href if message.links else None
  ```
</CodeGroup>

## List the latest message

`email.address()` mints a new local-part. `messages.list` on that address reads the inbox it just created. It does not take a subject filter.

<CodeGroup>
  ```typescript TypeScript theme={null}
  const mailbox = await client.email.address({
    domain: "your-domain.example",
    label: "signup",
  });
  const page = await mailbox.messages.list({ limit: 1 });
  const code = page.data[0]?.otp?.[0]?.value;
  ```

  ```python Python theme={null}
  mailbox = client.email.address(domain="your-domain.example", label="signup")
  page = mailbox.messages.list(limit=1)
  code = page.data[0].otp[0].value if page.data and page.data[0].otp else None
  ```
</CodeGroup>

To list an address you already chose, pass that full address to the CLI or `inbox` on the list endpoint. `q` matches the subject, sender, or recipient.

```bash theme={null}
devhelm email messages list --to signup@your-domain.example --limit 1
```

```bash theme={null}
curl "https://api.devhelm.io/api/v1/email/domains/your-domain.example/messages?inbox=signup&q=welcome&limit=1" \
  -H "Authorization: Bearer $DEVHELM_API_TOKEN" \
  -H "x-phelm-workspace-id: $DEVHELM_WORKSPACE_ID"
```

The JSON body is a cursor page. The code is `data[0].otp[0].value`.

## Next steps

<CardGroup cols={2}>
  <Card title="Wait for an email" icon="timer" href="/testing/email/wait">
    Block until the message that holds the code arrives.
  </Card>

  <Card title="Custom domains" icon="network-wired" href="/testing/email/custom-domains">
    Point a hostname you own at DevHelm.
  </Card>
</CardGroup>


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