HTML version: https://cooperemail.com/email-to-webhook

Email to webhook

# Email to webhook: turn every inbound email into a signed JSON POST

Create a Cooper inbox, register a public HTTPS URL, and every email that arrives is POSTed to that URL as JSON with an HMAC signature. The payload includes the sender, subject, extracted text, attachment metadata, and SPF, DKIM, and DMARC results. Free is $0 a month with no card: 5 inboxes, 5,000 emails a month, and 1 custom domain.

## Set up email to webhook in two calls

Onboard once to get a key and an inbox, then register the webhook on that inbox. POST /api/v1/inboxes/:id/notify takes a url and returns the signing secret on the first create. A second call with the same inbox updates the URL instead of adding a hook.

The URL must be public http or https. Localhost, private IPs, and names that resolve to them are rejected, and redirects are not followed. A trigger URL from Zapier, Make, or n8n works as the target.

```
AUTH=(-H "Authorization: Bearer $COOPER_API_KEY")
curl -s https://cooperemail.com/api/v1/inboxes/$INBOX/notify "${AUTH[@]}" \
  -H 'content-type: application/json' \
  -d '{"url":"https://example.com/hooks/cooper"}'
# Save the returned secret. It is redacted on later reads.
```

## What the POST looks like

Each delivery is one event: id (evt_...), type, created_at, and data. For message.received, data is the stored message: id, inbox_id, thread_id, from, to, subject, extracted_text, labels, attachments, and the auth results. extracted_text removes quoted history, which is usually what a parser or a model wants.

Headers: x-cooper-delivery is the event id, x-cooper-timestamp is unix seconds, and x-cooper-signature-v2 is v1= plus the hex HMAC-SHA256 of the timestamp, a dot, and the raw body. Reject a timestamp more than 5 minutes old and skip a delivery id you already handled.

```
import crypto from "node:crypto";

export function verifyCooper(secret, rawBody, headers, seen) {
  const id = headers["x-cooper-delivery"];
  const ts = headers["x-cooper-timestamp"];
  if (!id || seen.has(id)) return false;
  if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
  const expected = "v1=" + crypto.createHmac("sha256", secret)
    .update(ts + "." + rawBody).digest("hex");
  const ok = String(headers["x-cooper-signature-v2"] || "").split(",")
    .some((s) => s.trim().length === expected.length &&
      crypto.timingSafeEqual(Buffer.from(s.trim()), Buffer.from(expected)));
  if (ok) seen.add(id);
  return ok;
}
```

## More than message.received

POST /api/v1/webhooks registers a hook for a list of event types across up to 10 inboxes, or all inboxes when the filter is empty. Types include message.received, message.sent, message.bounced, message.complained, message.blocked, message.held, and domain.verified. Optional headers (up to 5, Authorization or X-*) are stored encrypted and sent on every delivery, so the target can require its own token.

5xx responses and network errors are retried twice. Every delivery is stored for 7 days, and POST /api/v1/webhooks/:id/deliveries/:deliveryId/redeliver sends one again with a fresh signature. After 20 consecutive final failures the hook disables itself and says why. rotate-secret mints a new secret and keeps the old one valid for 24 hours.

## Forward email to Slack or Discord

Slack and Discord incoming webhooks expect their own JSON shape, so point Cooper at a small function that verifies the signature and reposts the subject and extracted text. Keep the email body as untrusted text: do not let it change the destination or run commands.

## No public URL? Use the same events without a webhook

GET /api/v1/inboxes/:id/wait holds up to 55 seconds and returns as soon as unread mail exists. GET /api/v1/events?wait= long-polls the event log for 25 seconds, and GET /api/v1/events/stream is Server-Sent Events. A scheduled job can use an event consumer that remembers its cursor between runs.

## Use your own address

Inboxes default to cooperemail.com. Free includes 1 custom domain, so a webhook can sit behind invoices@yourcompany.com. Use a subdomain such as in.yourcompany.com if the root domain already receives mail elsewhere. Starter is $12 a month for 25 inboxes and 25,000 emails. Pro is $99 a month for 300 inboxes and 250,000 emails.

## Verify in Python

The same check for a Flask or FastAPI handler. Read the raw body before parsing JSON.

```
import hashlib, hmac, time

def verify_cooper(secret, raw_body: bytes, headers, seen):
    delivery = headers.get("x-cooper-delivery")
    ts = headers.get("x-cooper-timestamp", "0")
    if not delivery or delivery in seen or abs(time.time() - int(ts)) > 300:
        return False
    expected = "v1=" + hmac.new(secret.encode(), ts.encode() + b"." + raw_body,
                                hashlib.sha256).hexdigest()
    parts = [p.strip() for p in headers.get("x-cooper-signature-v2", "").split(",")]
    ok = any(hmac.compare_digest(expected, p) for p in parts)
    if ok:
        seen.add(delivery)
    return ok
```

## FAQ

### Can I send the webhook to Zapier, Make, or n8n?

Yes. A trigger URL from those tools is a public https URL, so it can be the webhook target. Verify the signature in a code step if the tool allows it.

### Is email to webhook free on Cooper?

Yes. Webhooks are on every plan. Free is $0 a month with no card: 5 inboxes, 5,000 emails a month, and 1 custom domain.

### How do I verify the webhook came from Cooper?

Compute HMAC-SHA256 with your secret over the timestamp, a dot, and the raw request body, prefix v1=, and compare it with x-cooper-signature-v2. Use the raw bytes, not re-serialized JSON, and reject timestamps more than 5 minutes off.

### What happens if my endpoint is down?

5xx and network errors are retried twice. Each delivery is kept for 7 days, and you can send one again with POST /api/v1/webhooks/:id/deliveries/:deliveryId/redeliver. Mail is stored either way, so you can also list it later.

### Are attachments included in the webhook?

The event lists attachment metadata. Download the bytes with GET /api/v1/inboxes/:id/messages/:msgId/attachments/:attId, or the full raw .eml from /raw.

## Related

[Inbound email API](/inbound-email-api) · [POST /webhooks](/docs/reference/webhooks) · [Stay in sync](/docs/stay-in-sync) · [Webhooks post](/blog/agent-email-webhooks-message-received) · [Pricing](/pricing) · [Docs](/docs) · [Pricing](/pricing)

Operator: Avatar 8 LLC (ops@avatar33.com). Last updated 2026-11-22.

Canonical: https://cooperemail.com/email-to-webhook
