# Inbound email

Receive email at your own domain: replies to your receipts, messages to a support address, documents customers send in. OnCharge receives the mail, parses it, stores it with its attachments and sends you an `email.received` webhook.

> **Early access: the API may change.** Fields on this page can still change before general availability.

## Addresses

- **On your domain.** Turn on inbound email for a [domain](https://oncharge.io/docs/messaging/domains) and add the `INBOUND` MX record it lists: an inbound subdomain such as `inbound.example.com`, pointing at `inbound.m.oncharge.io`. Mail to any address at that subdomain, such as `replies@inbound.example.com`, is received.
- **Before you have a domain.** Every account also has an address under OnCharge's inbound domain: `<anything>@<your account id>.inbound.m.oncharge.io`. The dashboard shows yours.

Use a subdomain for inbound mail, so your main domain's mailboxes keep working. To collect replies to the emails you send, set `reply_to` to an inbound address, for example `"reply_to": "order-1001@inbound.example.com"`, and use the part before the `@` to match the reply to the order.

## The webhook

Each received email sends an `email.received` [webhook](https://oncharge.io/docs/messaging/webhooks) with the inbound email's id in `data`. Fetch the email to read it:

```bash
curl https://app.oncharge.io/api/v1/inbound-emails/{id} \
  -H "Authorization: Bearer $ONCHARGE_MESSAGING_KEY"
```

```json title="Response 200"
{
  "id": "9e8d7c6b-5a4f-4e3d-b2c1-0a9f8e7d6c51",
  "from": "Alex Rivera <alex@example.net>",
  "to": ["order-1001@inbound.example.com"],
  "cc": [],
  "subject": "Re: Your order #1001 has shipped",
  "text": "Can you send it to my work address instead?",
  "html": "<p>Can you send it to my work address instead?</p>",
  "headers": { "message-id": "<…@example.net>", "in-reply-to": "<…@example.com>" },
  "attachments": [
    { "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d", "filename": "address.pdf", "content_type": "application/pdf", "size": 48213 }
  ],
  "received_at": "2027-01-15T15:20:44.000Z"
}
```

## Attachments

Attachments are not inlined in the email object. Ask for a short-lived download link:

```bash
curl https://app.oncharge.io/api/v1/inbound-emails/{id}/attachments/{attachment_id} \
  -H "Authorization: Bearer $ONCHARGE_MESSAGING_KEY"
```

```json title="Response 200"
{ "download_url": "https://…", "expires_at": "2027-01-15T15:35:44.000Z" }
```

Download the file before `expires_at`, and ask again for a new link after that. Treat every attachment as untrusted: scan it before anyone opens it.

## Endpoints

| Endpoint | Does |
|---|---|
| `GET /inbound-emails` | Lists received emails, newest first. |
| `GET /inbound-emails/{id}` | Reads one: `id`, `from`, `to`, `cc`, `subject`, `text`, `html`, `headers`, `attachments` and `received_at`. |
| `GET /inbound-emails/{id}/attachments/{attachment_id}` | Returns `download_url` and `expires_at` for one attachment. |

If you use OnCharge Support, its shared inbox can receive the same mail, so your team answers customers without another tool.
