# Emails

- Page: https://bytesms.com/docs/emails (markdown: https://bytesms.com/docs/emails.md)
- API base URL: https://api.bytesms.com/api (public resources under /api/v1)
- Auth: `Authorization: Bearer tp_live_…` — an API key from Dashboard → API Keys; keep it server-side (e.g. `BYTESMS_API_KEY`)
- All docs in one file: https://bytesms.com/llms-full.txt · OpenAPI 3.1: https://bytesms.com/openapi.json

Send, batch send, schedule, retrieve, reschedule and cancel emails with the Bytesms REST API (POST /v1/emails).

## Send an email

`POST https://api.bytesms.com/api/v1/emails`

Accepts one email and returns its id. The email is queued and handed to the sending server for your domain's region; follow its progress with [retrieve](https://bytesms.com/docs/emails#retrieve), [events](https://bytesms.com/docs/emails#events) or [webhooks](https://bytesms.com/docs/webhooks). Works with `full_access` and `sending_access` keys.

**Body**

- `from` (string, required): Sender address, optionally with a display name: `Acme <hello@example.com>`. Must be on a verified domain of the workspace (or `onboarding@mail.bytesms.com` for tests to your own account email). Optional when a `template` defines it.
- `to` (string | string[], required): Recipient address(es). At least one; at most 50 recipients across `to`, `cc` and `bcc`.
- `subject` (string, required): Subject line (no line breaks). Optional when a `template` defines it.
- `html` (string, optional): HTML body. Provide `html`, `text` or both (or a `template`). When only `html` is given, a plain-text part is generated from it.
- `text` (string, optional): Plain-text body.
- `cc` (string | string[], optional): Cc recipients.
- `bcc` (string | string[], optional): Bcc recipients (not shown in the message headers).
- `reply_to` (string | string[], optional): Reply-To address(es), up to 10, each `email@example.com` or `Name <email@example.com>`. Multiple addresses are joined into one `Reply-To` header; an invalid one is a `422`.
- `replyTo` (string, optional): Legacy camelCase form of `reply_to`: one string (several addresses separated by commas), same validation. When both are sent, `replyTo` wins. Prefer `reply_to` in new code.
- `scheduled_at` (string (ISO 8601), optional): Send later, e.g. `2026-10-01T09:00:00Z`. Must be in the future and at most 30 days ahead. The email is stored with `last_event: "scheduled"` until then and can be [rescheduled](https://bytesms.com/docs/emails#update) or [canceled](https://bytesms.com/docs/emails#cancel).
- `tags` ({ name, value }[], optional): Up to 50 tags for your own bookkeeping, echoed in webhook payloads. Names and values: ASCII letters, digits, `_` and `-`, at most 256 characters. An object `{ name: value }` is accepted too.
- `headers` (object, optional): Custom headers. Only `List-Unsubscribe`, `List-Unsubscribe-Post` (value `List-Unsubscribe=One-Click`, and only with an https `List-Unsubscribe` URL) and `X-Entity-Ref-ID` are passed through to the message (values up to 900 characters, no line breaks); other headers are not added to the email.
- `metadata` (object, optional): Free-form JSON object stored with the email for your own reference. It is shown on the email's page in the dashboard but is not returned by [retrieve](https://bytesms.com/docs/emails#retrieve) and is not sent to the recipient. Avoid the keys `tags` and `headers`: they are read as the email's tags and custom headers, and the top-level `tags` / `headers` fields replace them when set.
- `template` ({ id, variables } | { alias, variables }, optional): Render a published [template](https://bytesms.com/docs/templates) instead of `html`/`text`. Identify it with `id` (the template id or its alias) or `alias`; when both are set, `id` is used. `variables` is an object of values. See [Sending with a template](https://bytesms.com/docs/emails#template-send).
- `attachments` (—, optional): Not supported yet: any non-empty value is rejected with `422 attachments_not_supported`.

**Headers**

- `Idempotency-Key` (string, optional): Optional, 1–256 characters. Retries with the same key return the first response. See [Idempotency](https://bytesms.com/docs/idempotency).

**cURL**

```bash
# Send an email
curl -X POST 'https://api.bytesms.com/api/v1/emails' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"from":"Acme <hello@example.com>","to":["customer@example.com"],"subject":"Your order has shipped","html":"<p>Your order <strong>#4711</strong> is on its way.</p>","reply_to":"support@example.com","tags":[{"name":"category","value":"shipping"}]}'
```

**Node.js**

```js
// Send an email
const res = await fetch("https://api.bytesms.com/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "from": "Acme <hello@example.com>",
    "to": [
      "customer@example.com"
    ],
    "subject": "Your order has shipped",
    "html": "<p>Your order <strong>#4711</strong> is on its way.</p>",
    "reply_to": "support@example.com",
    "tags": [
      {
        "name": "category",
        "value": "shipping"
      }
    ]
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Send an email
res = requests.post(
    "https://api.bytesms.com/api/v1/emails",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "from": "Acme <hello@example.com>",
        "to": [
            "customer@example.com"
        ],
        "subject": "Your order has shipped",
        "html": "<p>Your order <strong>#4711</strong> is on its way.</p>",
        "reply_to": "support@example.com",
        "tags": [
            {
                "name": "category",
                "value": "shipping"
            }
        ]
    },
)
print(res.json())
```

**Response**

```json
{
  "id": "cmg4k2x7a0001l8v9h3q2d5rt"
}
```

### Sending with a template

With `template`, the published version of the template is rendered server-side. `from`, `subject` and `reply_to` in the request override the template's; `html`/`text`can't be combined with a template. Variable values are HTML-escaped in the HTML body. A variable the template uses without a fallback value must be provided, otherwise the send fails with `422`; an unpublished template is `422` too.

**cURL**

```bash
# Send with a template
curl -X POST 'https://api.bytesms.com/api/v1/emails' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"from":"Acme <hello@example.com>","to":"customer@example.com","template":{"id":"order-shipped","variables":{"first_name":"Jane","order_id":4711}}}'
```

**Node.js**

```js
// Send with a template
const res = await fetch("https://api.bytesms.com/api/v1/emails", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "from": "Acme <hello@example.com>",
    "to": "customer@example.com",
    "template": {
      "id": "order-shipped",
      "variables": {
        "first_name": "Jane",
        "order_id": 4711
      }
    }
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Send with a template
res = requests.post(
    "https://api.bytesms.com/api/v1/emails",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "from": "Acme <hello@example.com>",
        "to": "customer@example.com",
        "template": {
            "id": "order-shipped",
            "variables": {
                "first_name": "Jane",
                "order_id": 4711
            }
        }
    },
)
print(res.json())
```

`template: { alias: "order-shipped" }` works the same way when you prefer to name the alias explicitly.

### Who you can send from and to

- `from` must be on a domain with status `verified` in this workspace — otherwise `403 invalid_from_address` (or `403 validation_error` if the workspace has no verified domain yet).
- `onboarding@mail.bytesms.com` may only send to your own account email and to `@test.bytesms.com` test addresses.
- A domain-scoped API key may only send from its domain (`403 restricted_api_key`).
- Recipients on your suppression list (previous hard bounces and complaints) are skipped; if every recipient is suppressed, the email ends `failed`.

## Send a batch

`POST https://api.bytesms.com/api/v1/emails/batch`

Send up to 100 emails in one request. The body is a JSON **array** of email objects with the same fields as [send](https://bytesms.com/docs/emails#send), except `scheduled_at` (not supported in batches). Validation, sending rules and the quota check are all-or-nothing: either every email is accepted or none is. Supports `Idempotency-Key`.

**cURL**

```bash
# Send a batch
curl -X POST 'https://api.bytesms.com/api/v1/emails/batch' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '[{"from":"Acme <hello@example.com>","to":["a@example.com"],"subject":"Hi A","text":"Hello A"},{"from":"Acme <hello@example.com>","to":["b@example.com"],"subject":"Hi B","text":"Hello B"}]'
```

**Node.js**

```js
// Send a batch
const res = await fetch("https://api.bytesms.com/api/v1/emails/batch", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify([
    {
      "from": "Acme <hello@example.com>",
      "to": [
        "a@example.com"
      ],
      "subject": "Hi A",
      "text": "Hello A"
    },
    {
      "from": "Acme <hello@example.com>",
      "to": [
        "b@example.com"
      ],
      "subject": "Hi B",
      "text": "Hello B"
    }
  ]),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Send a batch
res = requests.post(
    "https://api.bytesms.com/api/v1/emails/batch",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json=[
        {
            "from": "Acme <hello@example.com>",
            "to": [
                "a@example.com"
            ],
            "subject": "Hi A",
            "text": "Hello A"
        },
        {
            "from": "Acme <hello@example.com>",
            "to": [
                "b@example.com"
            ],
            "subject": "Hi B",
            "text": "Hello B"
        }
    ],
)
print(res.json())
```

**Response**

```json
{
  "data": [
    {
      "id": "cmg4k2x7a0002l8v9w1b8n4qe"
    },
    {
      "id": "cmg4k2x7a0003l8v9c7m0p2ya"
    }
  ]
}
```

## Retrieve an email

`GET https://api.bytesms.com/api/v1/emails/{email_id}`

Returns the email with its current `last_event` and the full event history. Requires a `full_access` key.

**cURL**

```bash
# Retrieve an email
curl -X GET 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// Retrieve an email
const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", {
  method: "GET",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# Retrieve an email
res = requests.get(
    "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

**Response**

```json
{
  "object": "email",
  "id": "cmg4k2x7a0001l8v9h3q2d5rt",
  "from": "Acme <hello@example.com>",
  "to": [
    "customer@example.com"
  ],
  "cc": [],
  "bcc": [],
  "reply_to": "support@example.com",
  "subject": "Your order has shipped",
  "html": "<p>Your order <strong>#4711</strong> is on its way.</p>",
  "text": "Your order #4711 is on its way.",
  "created_at": "2026-09-28T08:15:02.114Z",
  "scheduled_at": null,
  "last_event": "delivered",
  "events": [
    {
      "type": "email.sent",
      "created_at": "2026-09-28T08:15:03.020Z",
      "data": {
        "email_id": "cmg4k2x7a0001l8v9h3q2d5rt",
        "from": "Acme <hello@example.com>",
        "to": [
          "customer@example.com"
        ],
        "subject": "Your order has shipped"
      }
    },
    {
      "type": "email.delivered",
      "created_at": "2026-09-28T08:15:05.480Z",
      "data": {
        "email_id": "cmg4k2x7a0001l8v9h3q2d5rt",
        "recipients": [
          "customer@example.com"
        ],
        "dsn": "2.0.0"
      }
    }
  ]
}
```

| last_event | Meaning |
| --- | --- |
| `queued` | Accepted, waiting to be handed to the sending server. |
| `scheduled` | Waiting for its `scheduled_at`. |
| `sent` | Accepted by our sending server for delivery. |
| `delivered` | The recipient's mail server accepted it (not necessarily the inbox). |
| `bounced` | The recipient's mail server permanently rejected it. |
| `complained` | The recipient marked it as spam. |
| `failed` | Not sent (e.g. suppressed recipient, sending error). |
| `canceled` | A scheduled email that was canceled. |

## List emails

`GET https://api.bytesms.com/api/v1/emails`

Newest first. Items have the same fields as retrieve, without `html`, `text` and `events`.

**Query**

- `limit` (integer, optional, default `20`): 1–100.
- `after` (string, optional): An email id: return older emails after it (next page).
- `before` (string, optional): An email id: return newer emails before it. Don't combine with `after`.

**cURL**

```bash
# List emails
curl -X GET 'https://api.bytesms.com/api/v1/emails?limit=20' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// List emails
const res = await fetch("https://api.bytesms.com/api/v1/emails?limit=20", {
  method: "GET",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# List emails
res = requests.get(
    "https://api.bytesms.com/api/v1/emails?limit=20",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

**Response**

```json
{
  "object": "list",
  "has_more": true,
  "data": [
    {
      "object": "email",
      "id": "cmg4k2x7a0001l8v9h3q2d5rt",
      "...": "..."
    }
  ]
}
```

## List an email's events

`GET https://api.bytesms.com/api/v1/emails/{email_id}/events`

Every recorded event, oldest first: `email.sent`, `email.delivered`, `email.delivery_delayed`, `email.bounced`, `email.complained`, `email.failed`. `data` holds event details such as the bounce reason.

**Response**

```json
{
  "data": [
    {
      "type": "email.sent",
      "created_at": "2026-09-28T08:15:03.020Z",
      "data": {
        "email_id": "cmg4k2x7a0001l8v9h3q2d5rt",
        "from": "Acme <hello@example.com>",
        "to": [
          "nobody@example.com"
        ],
        "subject": "Hello"
      }
    },
    {
      "type": "email.bounced",
      "created_at": "2026-09-28T08:15:06.901Z",
      "data": {
        "email_id": "cmg4k2x7a0001l8v9h3q2d5rt",
        "bounce": {
          "type": "Permanent",
          "subType": "5.1.1",
          "reason": "550 5.1.1 User unknown"
        },
        "recipients": [
          "nobody@example.com"
        ]
      }
    }
  ]
}
```

## Reschedule an email

`PATCH https://api.bytesms.com/api/v1/emails/{email_id}`

Change the `scheduled_at` of an email that is still `scheduled`; any other state is `422 validation_error`.

**Body**

- `scheduled_at` (string (ISO 8601), required): New send time, in the future and at most 30 days after the email was first created.

**cURL**

```bash
# Reschedule
curl -X PATCH 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{"scheduled_at":"2026-10-01T09:00:00Z"}'
```

**Node.js**

```js
// Reschedule
const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt", {
  method: "PATCH",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "scheduled_at": "2026-10-01T09:00:00Z"
  }),
});
console.log(await res.json());
```

**Python**

```python
import requests

# Reschedule
res = requests.patch(
    "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
    json={
        "scheduled_at": "2026-10-01T09:00:00Z"
    },
)
print(res.json())
```

**Response**

```json
{
  "object": "email",
  "id": "cmg4k2x7a0001l8v9h3q2d5rt"
}
```

## Cancel a scheduled email

`POST https://api.bytesms.com/api/v1/emails/{email_id}/cancel`

Cancels an email that is still `scheduled`. Its `last_event` becomes `canceled` and its quota is released.

**cURL**

```bash
# Cancel
curl -X POST 'https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel' \
  -H 'Authorization: Bearer tp_live_xxxxxxxxx'
```

**Node.js**

```js
// Cancel
const res = await fetch("https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel", {
  method: "POST",
  headers: {
    Authorization: "Bearer tp_live_xxxxxxxxx",
  },
});
console.log(await res.json());
```

**Python**

```python
import requests

# Cancel
res = requests.post(
    "https://api.bytesms.com/api/v1/emails/cmg4k2x7a0001l8v9h3q2d5rt/cancel",
    headers={"Authorization": "Bearer tp_live_xxxxxxxxx"},
)
print(res.json())
```

**Response**

```json
{
  "object": "email",
  "id": "cmg4k2x7a0001l8v9h3q2d5rt"
}
```

> **Note: Legacy endpoint**
>
> `POST /api/v1/emails/send` accepts the same body but returns the full internal message record and a different error format. It is kept for existing integrations; use `POST /api/v1/emails` for new code.
