# Sandbox

The sandbox lets you try the API without sending real email. A test key simulates everything it sends, and a test address ends the way its name says.

## Test keys

A test key starts with `os_test_`. Make one in [API keys](https://opensend.sh/dashboard/api-keys) by choosing Test mode, or send `mode` as `test` when you create a key.

cURL:

```bash
curl -X POST "$OPENSEND_API_URL/v1/api-keys" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Marketing site",
  "access": "sending"
}'
```

TypeScript:

```ts
await opensend.apiKeys.create({
  name: 'Marketing site',
  access: 'sending',
})
```

CLI:

```bash
opensend api-keys create --name 'Marketing site' --access sending
```

MCP:

```json
{
  "name": "api_keys_create",
  "arguments": {
    "name": "Marketing site",
    "access": "sending"
  }
}
```

For a test key, the body of that request is:

```json
{
  "name": "Continuous integration",
  "mode": "test"
}
```

- Every email a test key sends is simulated. It reaches nobody and is never handed to the sending service.
- The sender can be any address. A test key needs no verified domain, so you can try the API before your DNS records are in.
- A test key only sends. It reads the emails of the sandbox and no others, and `key_test_access` refuses one with `full` access.

## Test addresses

A test address reaches nobody, with any key. It is on `opensend.test`, a domain nobody can own, and the name before the @ says how the email ends.

| Address | What happens | Last status |
| --- | --- | --- |
| `delivered@opensend.test` | Sent, then delivered | `delivered` |
| `opened@opensend.test` | Delivered, then opened | `opened` |
| `clicked@opensend.test` | Delivered, opened, then a link is clicked | `clicked` |
| `delayed@opensend.test` | Delayed once, then delivered | `delivered` |
| `complained@opensend.test` | Delivered, then marked as spam | `complained` |
| `bounced@opensend.test` | Sent, then refused for good | `bounced` |
| `suppressed@opensend.test` | Held back before sending, as an address on the suppression list is | `failed` |
| `failed@opensend.test` | Fails before it is sent | `failed` |

A label after a plus sign tells your tests apart: `bounced+signup@opensend.test` ends like `bounced@opensend.test`.

- With a live key every recipient of an email is a test address, or none is. A mix is refused with `sandbox_mixed`.
- With a test key any mix is fine, and a real address counts as delivered.
- `sandbox_address`: the name before the @ is not one of the test addresses.

> Coming from Resend: `delivered@resend.dev`, `bounced@resend.dev`, `complained@resend.dev`, `suppressed@resend.dev` are test addresses here too, so tests written for Resend keep reaching nobody.

## What a test email is

A test email has `mode` set to `test`. Everything before the hand-over is real: the input is checked, a template is filled in, an idempotency key works and a scheduled email waits for its time.

cURL:

```bash
curl -X POST "$OPENSEND_API_URL/v1/emails" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "from": "Acme <hello@mail.example.com>",
  "to": "ada@example.com",
  "subject": "Your receipt for November",
  "html": "<p>Thanks for your order.</p>"
}'
```

TypeScript:

```ts
await opensend.emails.send({
  from: 'Acme <hello@mail.example.com>',
  to: 'ada@example.com',
  subject: 'Your receipt for November',
  html: '<p>Thanks for your order.</p>',
})
```

CLI:

```bash
opensend emails send \
  --from 'Acme <hello@mail.example.com>' \
  --to ada@example.com \
  --subject 'Your receipt for November' \
  --html '<p>Thanks for your order.</p>'
```

MCP:

```json
{
  "name": "emails_send",
  "arguments": {
    "from": "Acme <hello@mail.example.com>",
    "to": "ada@example.com",
    "subject": "Your receipt for November",
    "html": "<p>Thanks for your order.</p>"
  }
}
```

Sent with this body, the same request ends as a bounce and reaches nobody:

```json
{
  "from": "Acme <hello@mail.example.com>",
  "to": "bounced@opensend.test",
  "subject": "Your receipt",
  "text": "Thanks for your order."
}
```

- The answer says `queued`. The events follow at once: `sent`, then what the address stands for.
- Your webhooks get the same events as for a real email, with `mode` set to `test` in `data`, so one endpoint can tell the two apart.
- A list takes `mode`: `test` for the sandbox, `live` for real email.
- Test emails are left out of the metrics and never touch the suppression list.
- A test email starts no automation, so a test never sets off real mail.

cURL:

```bash
curl "$OPENSEND_API_URL/v1/emails?status=bounced&limit=20" \
  -H "Authorization: Bearer $OPENSEND_API_KEY"
```

TypeScript:

```ts
await opensend.emails.list({
  status: 'bounced',
  limit: 20,
})
```

CLI:

```bash
opensend emails list --status bounced --limit 20
```

MCP:

```json
{
  "name": "emails_list",
  "arguments": {
    "status": "bounced",
    "limit": 20
  }
}
```

## What it counts

Test emails do not count towards your plan and are never charged. They have an allowance of their own: each month a workspace may send as many test emails as its plan allows transactional ones. Past that a send is refused with `sandbox_limit` until the first of the month.

## In broadcasts and automations

A contact with a test address is simulated too. Put `bounced@opensend.test` in an audience and a broadcast reaches everyone else, while that one copy ends as a bounce within a couple of minutes.
