# Webhooks

> Events pushed to your endpoint, signed, retried and in order per e-mail.

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

For agents: Mail webhooks: mail webhooks create <url> --events …; POST JSON {id, type, createdAt, email {id,to,from,subject,tags}, bounce {kind, code, message}}; header sypnia-signature t=…,v1=HMAC-SHA256 over t.body, verifyWebhook(request, secret) rejects >5 min; 2xx within 10 s; retries with backoff 24 h then undelivered + webhooks replay; ordered per e-mail; dedupe by id; paused after 3 days failing; Sypnia Run function target run://name.

```bash
npx @sypnia/mail webhooks create https://laespiga.co/api/mail-events --events delivered,bounced,complained
```

Each event is a `POST` with a JSON body:

```json
{
  "id": "evt_01JD…",
  "type": "bounced",
  "createdAt": "2026-11-17T14:03:22Z",
  "email": { "id": "em_01JD…", "to": "ana@example.com", "from": "pedidos@laespiga.co", "subject": "Tu pedido #1042 está listo", "tags": { "kind": "order-ready" } },
  "bounce": { "kind": "hard", "code": "5.1.1", "message": "The email account that you tried to reach does not exist." }
}
```

## Checking the signature

Each request carries `sypnia-signature: t=<unix>,v1=<hmac-sha256>` over `<t>.<body>` with the webhook's secret. `verifyWebhook(request, secret)` from `@sypnia/mail/server` checks it and refuses requests older than 5 minutes.

## Delivery

- Your endpoint must answer `2xx` within 10 seconds.
- Failures are retried with backoff for 24 hours; after that the event stays in the log, marked undelivered, and `mail webhooks replay` sends it again.
- Events of one e-mail arrive in order; events of different e-mails can arrive in any order. Use `id` to ignore duplicates.
- A webhook that fails for 3 days in a row is paused and you are notified.

With **Sypnia Run**, a function in the same project can be the webhook without a public URL: `--target run://mail-events`.
