# The send API

> One call to send an e-mail, what it checks, and how to send many safely.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://mail.docs.sypnia.com/sending/send-api/

For agents: Mail send API: mail.send({from, to, cc, bcc, replyTo, subject, html, text | template+data, tags, idempotencyKey}); checks scope send (403), verified from domain (422 domain_not_verified), suppression (skipped, suppressed[]; 422 all_suppressed), ≤50 recipients (400), ≤10 MB (413), rate/daily limit (429 retry-after); 202 {id, suppressed} = queued; idempotencyKey dedupes 24 h; sendBatch up to 100 personal messages; tags up to 10 keys returned on events.

```ts
const { id } = await mail.send({
  from: 'La Espiga <pedidos@laespiga.co>',
  to: ['ana@example.com'],
  replyTo: 'hola@laespiga.co',
  subject: 'Tu pedido #1042 está listo',
  html: '<p>Hola Ana, ya puedes recogerlo.</p>',
  text: 'Hola Ana, ya puedes recogerlo.',
  tags: { kind: 'order-ready', order: '1042' },
  idempotencyKey: 'order-ready-1042',
});
```

## What it checks before answering

| Check                                             | If it fails                                                                                |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| the key's scope includes `send`                   | `403 forbidden`                                                                            |
| the `from` domain is verified in the project      | `422 domain_not_verified`                                                                  |
| no recipient is on the suppression list           | that recipient is skipped and reported in `suppressed[]`; if all are, `422 all_suppressed` |
| at most 50 recipients across `to`, `cc` and `bcc` | `400 too_many_recipients`                                                                  |
| size with attachments at most 10 MB               | `413 too_large`                                                                            |
| the project's rate and daily limit                | `429 rate_limited` with `retry-after`                                                      |

The answer is `202 Accepted` with `{ id, suppressed }`. Accepted means queued, not delivered: [Events](https://mail.docs.sypnia.com/events) tell you the rest.

## Idempotency

With `idempotencyKey`, sending the same key again within 24 hours returns the first e-mail's id and sends nothing. Use it whenever a retry could repeat a send.

## Many e-mails

`mail.sendBatch([...])` takes up to 100 messages in one call, each with its own recipient and data, and returns an id per message. Every message is personal: one recipient, one e-mail. Batches still count against the rate limit.

## Tags

`tags` are up to 10 keys of your own; they come back on every event of the e-mail and you can filter the log by them.
