Webhooks

A webhook sends a server's events to a URL of your application as they happen: a message accepted, delivered, deferred or bounced, opened or clicked, a recipient unsubscribed or reported it as spam, a problem in a domain's DNS. Requests are signed as Standard Webhooks describes, so the reference libraries (and many frameworks) verify them as they are. For applications written for the webhooks of Postal, Mailgun, SendGrid or Postmark, Karta also sends them in those providers' formats (Formats).

Webhooks are managed on the server's Webhooks page of the admin interface (Managing organisations, servers and keys), over the Karta API (scopes webhooks:read and webhooks:write), and those in Mailgun's and SendGrid's formats also over those providers' webhook settings APIs (Managed with Mailgun's or SendGrid's API). All three show and change the same webhooks.

Events

Each message event is about one recipient of one outgoing message. Every event is sent once Karta has recorded it: in the same database transaction, so an event is never sent for something that did not happen, and never lost for something that did.

TypeWhen
message.acceptedKarta accepted the message for the recipient and queued it
message.suppressedthe recipient was on the server's suppression list when the message was accepted; it is not delivered
message.deliveredthe recipient's mail server accepted the message
message.deferreda delivery attempt failed temporarily; Karta tries again
message.bounceddelivery failed for good: the recipient's server refused it, or the retry period ended
message.openedthe recipient opened the message (open tracking)
message.clickedthe recipient followed a tracked link
message.unsubscribedthe recipient unsubscribed with one click; the address is now suppressed
message.complainedthe recipient reported the message as spam (a feedback report); the address is now suppressed
domain.dns_faileda DNS health check of a verified domain of the server's organisation turned to a problem

A webhook subscribes to some of these types, or to all of them (["*"], which includes types added later). webhook.test is sent only when you ask for a test event. Messages with an empty envelope sender (the delivery status notifications Karta sends itself) have no events.

domain.dns_failed is sent once per problem: when a check (SPF, DKIM, DMARC, MX, ...) of a verified domain turns to fail, for every server of the domain's organisation, and again only after the check passed in between. The hourly checks and Check DNS on the domain's page both count.

The request

POST /karta/events HTTP/1.1
Host: hooks.example.com
Content-Type: application/json
User-Agent: Karta-Webhooks
webhook-id: 019adf2e-5c4b-7d1a-9e2f-3a4b5c6d7e8f
webhook-timestamp: 1796206500
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=

{"type":"message.delivered","timestamp":"2026-12-02T10:15:00.000000Z","version":1,"data":{...}}
  • webhook-id is the event's id: the same for every attempt and every replay of that event. Use it to drop duplicates.
  • webhook-timestamp is when the request was signed, in seconds since 1970.
  • webhook-signature is v1, and the base64 HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<body>. After a secret rotation it carries two signatures, separated by a space.
  • The body is JSON: type, timestamp (when the event happened, UTC), version (1) and data.

data of every message event:

{
  "server_id": "6f1c…",
  "message": {
    "id": "019adf2e-…",
    "message_id": "<019adf2e-…@mail.example.com>",
    "mail_from": "ann@shop.example",
    "from": "ann@shop.example",
    "subject": "Your order",
    "tag": "orders",
    "tags": ["orders"],
    "variables": {"order": "1042"},
    "size": 18734,
    "created_at": "2026-12-02T10:14:58.517301Z"
  },
  "recipient": {"id": "019adf2e-…", "address": "bob@example.net"}
}

message.delivered, message.deferred and message.bounced add delivery: attempt, status, code and enhanced_code (the receiving server's reply), details (its text, or Karta's), mx_host, remote_ip, local_ip, tls_version, tls_cipher, tls_policy, and for message.deferred next_attempt_at. message.opened and message.clicked add tracking: ip_network (the client's network, never its address), user_agent, for an open first (true when it is the recipient's first recorded open), and for a click url and link_id. message.suppressed adds suppression: the reason the address is on the list (manual, unsubscribe, hard_bounce or complaint). message.complained adds complaint: feedback_type (RFC 5965's type, abuse for one Karta does not know), user_agent, version, reported_domain, source_ip, and the report's own and the quoted message's Message-IDs, as the report wrote them. What the report says about the message is a record, never what decided the event.

data of domain.dns_failed:

{
  "server_id": "6f1c…",
  "server": {"name": "Shop", "slug": "shop", "organisation": "acme"},
  "domain": {"id": "019adf2e-…", "name": "shop.example"},
  "checked_at": "2026-12-02T11:00:04.381022Z",
  "failed": ["spf"],
  "checks": {
    "spf": {"status": "fail", "problem": "There is no SPF record at shop.example: …"},
    "dkim": {"status": "pass"},
    "mx": {"status": "warn", "problem": "There is no MX record: …"}
  }
}

failed names the checks that turned to fail in this run; checks has every check with a result, its status (pass, warn, fail, missing) and, unless it passed, what was found.

A field whose value Karta does not know is left out. Version 1 changes only by adding fields and types: ignore what you do not know.

Verifying a request

Keep the webhook's secret (whsec_…, shown once when the webhook is made or its secret rotated) where your application keeps its secrets. For each request:

  1. Read the three headers; refuse the request when one is missing.
  2. Refuse it when webhook-timestamp is more than five minutes from your clock.
  3. Compute the HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<body> (the body exactly as received, before parsing) with the secret's key: the base64 after whsec_, decoded.
  4. Accept the request when one of the space-separated v1,<signature> entries matches, compared in constant time.

The Standard Webhooks libraries do this (standardwebhooks for Ruby, Python, JavaScript, Go, Rust, Java, C#, PHP); in Elixir, for example:

"whsec_" <> encoded = secret
key = Base.decode64!(encoded)
expected = :crypto.mac(:hmac, :sha256, key, [id, ".", timestamp, ".", body])

signatures
|> String.split(" ")
|> Enum.any?(fn
  "v1," <> given ->
    case Base.decode64(given) do
      {:ok, given} -> :crypto.hash_equals(given, expected)
      :error -> false
    end

  _ ->
    false
end)

Answer with a 2xx status as soon as the request is stored; do the work later. Anything else is a failure.

Rotating the secret

POST /api/v2/webhooks/{id}/secret gives the webhook a new secret. For a day (or keep_previous_for seconds, at most a week; 0 for none) every request carries a signature with the previous secret too, so you can deploy the new secret without losing a request. (In Mailgun's and SendGrid's formats the new key signs at once; in SendGrid's it is a new key pair, whose public key the webhook shows. Postal's and Postmark's formats have no secret of their own.)

Formats

A webhook's format is chosen when it is added and does not change (add another webhook for another format):

FormatBodySignatureEvents
standard (the default)Karta's, as aboveStandard Webhooks, the webhook's whsec_ secretall
postalPostal's: event, timestamp, payload, uuidRSA, the organisation's key: X-Postal-Signature, X-Postal-Signature-256, X-Postal-Signature-KIDthose Postal has
mailgunMailgun's: signature, event-dataHMAC-SHA256 of timestamp and token, the webhook's signing keythose Mailgun has
sendgridSendGrid's Event Webhook: an array of eventsECDSA (P-256) of timestamp and body, the webhook's key pair: X-Twilio-Email-Event-Webhook-Signature, -Timestampthose SendGrid has
postmarkPostmark's: one record by RecordTypenone (Postmark signs nothing): a user name and password in the URLthose Postmark has

Retries, dead letters, replays, test events, switching off and where requests go are the same in every format. Use standard for anything new: its signature covers the time and the event's id, which Postal's and Mailgun's do not, and Postmark's format has none (see below).

Postal's format

For applications that receive Postal's webhooks: point them at Karta and keep their code. The body is Postal's:

{"event":"MessageSent","timestamp":1796206500.104227,"payload":{"message":{"id":"019adf2e-…","token":"3poaymrijsmhxnfh","direction":"outgoing","message_id":"019adf2e-…@mail.example.com","to":"bob@example.net","from":"ann@shop.example","subject":"Your order","timestamp":1796206498.517301,"spam_status":"NotChecked","tag":"orders"},"status":"Sent","details":"250 2.0.0 Ok: queued as 4ABC","output":"250 2.0.0 Ok: queued as 4ABC","sent_with_ssl":true,"timestamp":1796206500.104227,"time":null},"uuid":"019adf2e-5c53-…"}
Karta's eventPostal's eventpayload
message.deliveredMessageSentmessage, status (Sent), details, output, sent_with_ssl, timestamp, time
message.deferredMessageDelayedthe same, status SoftFail
message.bouncedMessageDeliveryFailedthe same, status HardFail
message.suppressedMessageHeldthe same, status Held, details "Recipient (…) is on the suppression list (reason: …)"
message.openedMessageLoadedmessage, ip_address, user_agent
message.clickedMessageLinkClickedmessage, url, token, ip_address, user_agent
message.complainedMessageSpamComplaintmessage, details, timestamp, time
domain.dns_failedDomainDNSErrorserver, domain, uuid, dns_checked_at, and the status (OK, Missing, Invalid) and error of SPF, DKIM, MX and the return path

message.accepted and message.unsubscribed have no Postal event, and a webhook in Postal's format does not get them. As in the Postal-compatible API, a Postal message is one recipient: message.id is the recipient's id (a UUID where Postal has a number) and message.token the token that API returns. uuid is the delivery's id: the same on every attempt and replay. What Karta does not have is sent as Postal sends a missing value: time is null (Karta does not measure how long a delivery took), spam_status is NotChecked (Karta does not scan outgoing mail), ip_address is the client's network, token of a click is Karta's link id. Postal's MessageBounced (a bounce message received later), SendLimitApproaching and SendLimitExceeded are not sent. Postal sends DomainDNSError after every hourly check while a problem lasts; Karta sends it once per problem. The test event is webhook.test.

The signature: X-Postal-Signature is the base64 RSA-SHA1 signature of the body, X-Postal-Signature-256 the RSA-SHA256 one, and X-Postal-Signature-KID names the key. Each organisation has its own RSA key, and only that organisation's requests carry it: a request signed for one organisation does not verify with another organisation's key, whose set has no key with that id. The organisation's public key is at its own JWK set, whose address the webhook's page and GET /api/v2/postal-key show (https://…/.well-known/jwks/<token>; a JWK set in Postal's shape, the active key and those retired in the last week), and the operator can publish it as a DNS record of the form Postal prints (v=DKIM1; t=s; h=sha256; p=…;) where your receivers look it up. To verify a request, check X-Postal-Signature-256 against the body as received with that key (RSA PKCS #1 v1.5, SHA-256), or X-Postal-Signature (SHA-1) as receivers of older Postal versions do.

Postal's signature covers the body only: no time, no recipient. A request recorded once can be sent to your receiver again later, and a request meant for another receiver of the same organisation verifies too (the key is the organisation's). Check the uuid against those you have seen, and that the message is one of yours.

Moving from Postal. Receivers that check Postal's signatures keep their code; they take the organisation's public key instead of Postal's, from its JWK set or the DNS record (Administration).

Header authentication

A webhook may carry one extra header of your choosing with a secret value, for a receiver behind a gateway or a no-code tool that cannot check a signature (for example Authorization: Bearer … or X-Api-Key: …). It is sent with every request in addition to the format's signature, never instead of it. Set it over the API (auth_header, auth_header_value) or on the webhook's page; the value is encrypted by the vault and shown once, when it is set. A read gives only the header's name.

  • https:// only, as the URL itself (or http:// where the instance allows it, for development and tests).
  • The name must be an HTTP header name (a token: letters, digits and !#$%&'*+-.^_`|~). Host, Content-*, Transfer-Encoding, Connection, Upgrade, TE, Trailer, Proxy-*, User-Agent and every format's signature headers (webhook-*, X-Postal-Signature*, X-Twilio-Email-Event-Webhook-*, X-Mailgun-*, X-PM-*) are refused. Authorization is allowed only while the URL carries no user name and password, which are sent in that same header.
  • The value must be printable ASCII, at most 1,024 bytes, without line breaks or white space at either end.

What it does not protect: the body's integrity (a changed body is not detected) and a request sent again (a recorded request authenticates again). Check the format's signature, and the webhook-id or uuid when those matter.

Mailgun's format

For applications that receive Mailgun's webhooks:

{
  "signature": {
    "timestamp": "1796378400",
    "token": "4f6c1e9b2d3a5c7e8f0a1b2c3d4e5f60718293a4b5c6d7e8f9",
    "signature": "130decf6da373e1bb63da6cb1669b6a778046f6465e9bf831f55e362b94cf77c"
  },
  "event-data": {"id": "AZrfLlxLfRqeLzpLXG1-jw", "event": "delivered", "timestamp": 1796206500.104227, "recipient": "bob@example.net", "delivery-status": {"code": 250, …}, …}
}
Karta's eventMailgun's event
message.acceptedaccepted
message.delivereddelivered
message.deferredfailed, severity temporary, reason generic (with delivery-status.retry-seconds)
message.bouncedfailed, severity permanent, reason bounce (old when the retry period ran out)
message.suppressedfailed, severity permanent, reason suppress-bounce, suppress-unsubscribe or suppress-complaint
message.opened, message.clickedopened, clicked (ip is the client's network)
message.unsubscribedunsubscribed
message.complainedcomplained, severity permanent, reason suppress-complaint

domain.dns_failed has no Mailgun event. event-data has Mailgun's fields as Karta's Mailgun events API gives them; message.headers.to is the recipient's address, and id comes from the event's id (the same on every attempt). The test event is webhook.test.

The signature: signature is the hexadecimal HMAC-SHA256 of timestamp followed by token, with the webhook's signing key (64 hexadecimal digits, shown once when the webhook is added or its key rotated) as the key, as Mailgun signs. Keep the key where you kept Mailgun's webhook signing key. Verify as for Mailgun: compare the signature in constant time, refuse a timestamp more than a few minutes old, and refuse a token you saw before. The body itself is not signed.

SendGrid's format

For applications that receive SendGrid's Event Webhook. The body is a JSON array of events, followed by a carriage return and line feed as SendGrid's:

POST /sendgrid/events HTTP/1.1
Content-Type: application/json
X-Twilio-Email-Event-Webhook-Signature: MEUCIQD…
X-Twilio-Email-Event-Webhook-Timestamp: 1796206500

[{"email":"bob@example.net","timestamp":1796206500,"smtp-id":"<019adf2e-…@shop.example>","event":"delivered","category":["orders"],"sg_event_id":"AZrfLlxLfRqeLzpLXG1+jw==","sg_message_id":"019adf2e-…@shop.example.019adf2e-…","response":"250 2.0.0 Ok: queued as 4ABC","order":"1042"}]

Karta sends one event per request. SendGrid collects events for up to 30 seconds, so receivers take arrays of any length; each event keeps its own retries and replays.

Karta's eventSendGrid's event
message.acceptedprocessed
message.suppresseddropped, reason Bounced Address, Unsubscribed Address or Spam Reporting Address, status 5.0.0
message.delivereddelivered, response (the server's reply)
message.deferreddeferred, response, attempt, domain, from
message.bouncedbounce, reason (the server's reply), status (its enhanced code), type bounce, or blocked when the retry period ran out
message.opened, message.clickedopen, click: useragent, ip (the client's network), for a click url; sg_machine_open is false
message.unsubscribedunsubscribe
message.complainedspamreport

domain.dns_failed has no SendGrid event, nor have SendGrid's group_unsubscribe and group_resubscribe a Karta event yet. Every event has email, timestamp, smtp-id (the Message-ID), event, category (the message's tags), sg_event_id (from the event's id: the same on every attempt) and sg_message_id: the Message-ID without its angle brackets, which the SendGrid-compatible API answers as X-Message-Id, a dot and the recipient's id. Karta's Message-IDs have dots, so take the part before the last dot to find the X-Message-Id. The message's variables (SendGrid's custom arguments) are fields of their own unless an event field has their name. Not sent: pool, asm_group_id, url_offset, bounce_classification, tls, cert_err and marketing campaign fields. The test event is webhook.test.

The signature, as SendGrid's Signed Event Webhook: every webhook has an ECDSA key pair of its own (P-256). Karta keeps the private key, encrypted, and never shows it; the webhook shows its public key (public_key, the base64 of its DER form, as SendGrid shows its verification key), at any time. X-Twilio-Email-Event-Webhook-Signature is the base64 ECDSA signature, with SHA-256, of the X-Twilio-Email-Event-Webhook-Timestamp header followed by the body as received. SendGrid's libraries verify it as they are, with Karta's public key, for example sendgrid-ruby:

event_webhook = SendGrid::EventWebhook.new
key = event_webhook.convert_public_key_to_ecdsa(public_key)
event_webhook.verify_signature(key, request.body.read,
                               request.headers["X-Twilio-Email-Event-Webhook-Signature"],
                               request.headers["X-Twilio-Email-Event-Webhook-Timestamp"])

Those libraries do not look at the timestamp's age: refuse old ones yourself, and drop events whose sg_event_id you have seen.

Postmark's format

For applications that receive Postmark's webhooks. One event per request, Postmark's record:

{"RecordType":"Delivery","MessageStream":"outbound","MessageID":"019adf2e-…","Recipient":"bob@example.net","Tag":"orders","DeliveredAt":"2026-12-02T10:15:00.104227Z","Details":"250 2.0.0 Ok: queued as 4ABC","Metadata":{"order":"1042"}}
Karta's eventPostmark's RecordType
message.deliveredDelivery
message.bouncedBounce, Type HardBounce (1) when the server refused the message, SoftBounce (4096) when the retry period ran out
message.deferredBounce, Type Transient (2): Karta tries again
message.openedOpen (FirstOpen for the recipient's first open)
message.clickedClick
message.unsubscribedSubscriptionChange, SuppressSending true, SuppressionReason ManualSuppression
message.complainedSpamComplaint, Inactive true and CanActivate false

message.accepted, message.suppressed (Postmark refuses a message to a suppressed address when it is sent) and domain.dns_failed have no record type. MessageID is the message's id (one per message, as Postmark's), Tag its first tag, Metadata its variables. What Karta does not have is sent as Postmark sends what it does not know, or left out: no ServerID (Postmark numbers its servers) and no bounce ID (there is no bounce API to use it with); a bounce's Content is empty and DumpAvailable false, Inactive false and CanActivate true (a bounce does not suppress the address in Karta); Platform is Unknown, ReadSeconds 0, Client and OS have Unknown names, Geo has only IP (the client's network); ClickLocation is HTML. The test event is webhook.test.

Postmark does not sign its webhooks, and neither does Karta in its format: give the webhook a URL with a user name and password (https://user:password@hooks.example.com/…, see Where requests go) and check them, as Postmark's users do. Every request carries X-PM-Webhook-Trace-Id, the delivery's id, the same on every attempt: drop requests whose id you have seen. A webhook in Postmark's format has no secret to rotate.

Managed with Mailgun's or SendGrid's API

Applications that set up their webhooks with Mailgun's or SendGrid's API can do so against Karta, with an API key that has webhooks:read (to read) and webhooks:write (to change). They see and change the server's webhooks in that provider's format, however they were made, the Karta API included.

Mailgun (/mailgun/v3/domains/<domain>/webhooks, as mailgun-ruby's Mailgun::Webhooks calls it). Each of Mailgun's webhook names has up to three URLs: accepted (message.accepted), delivered, permanent_fail (message.bounced and message.suppressed), temporary_fail (message.deferred), opened, clicked, unsubscribed and complained (message.complained). Karta keeps one webhook per URL, with the types of every name it is listed for: setting a name's URLs gives those webhooks its types (adding a webhook for a new URL) and takes them from the others, and a webhook left without types is removed. Setting the same URLs again changes nothing; getting or removing a name without URLs is "Webhook not found". The domain must be one of the organisation's verified domains; the webhooks serve every domain of the server. Mailgun signs all of an account's webhooks with one key, so the webhooks made this way share the signing key of the server's oldest webhook in Mailgun's format; rotating it (POST /api/v2/webhooks/{id}/secret) rotates it for every webhook that shares it and shows the new key once. Mailgun's v4 webhooks API and its signing key endpoints are not served.

SendGrid (/sendgrid/v3/user/webhooks/event/..., as sendgrid-ruby calls it): settings/all lists the webhooks (max_allowed 20), POST settings adds one, GET, PATCH and DELETE settings/<id> read, change and remove one, and without an id GET and PATCH settings act on the oldest (adding it when there is none), as for SendGrid's accounts with one webhook. A webhook's id is Karta's, its friendly_name its name; its events are SendGrid's switches (processed, dropped, delivered, deferred, bounce, open, click, unsubscribe; at least one on). spam_report, group_unsubscribe and group_resubscribe stay off. A URL is used by one webhook only. settings/signed/<id> gives the webhook's public_key, the key your application verifies with; Karta signs every request, so PATCH settings/signed takes {"enabled": true} only. POST test sends a webhook.test event to the webhook with the id or url given. OAuth is not available: use a user name and password in the URL.

Retries, dead letters and replays

A request fails when the answer is not 2xx (a redirect too: Karta does not follow redirects), when Karta cannot connect, or when no answer comes within 15 seconds. A failed delivery is tried again after 1, 5, 15 and 30 minutes, 1, 2, 4, 8, 12 and 16 hours, and a day: 12 attempts over about three days, each wait 10% shorter or longer at random. After the last one the delivery is failed: a dead letter.

The API lists a webhook's deliveries (state: pending, succeeded, failed) with every request made: the status, the start of the answer's body or the error. A delivery can be sent again on its own, and all of a webhook's dead letters (or delivered ones too) in a time range at once; a replay sends the same event with the same webhook-id, with every attempt anew.

Karta sends at most four requests at a time to one webhook, and in no guaranteed order: order events by their timestamp. A delivery under way is claimed in the database for the length of the request and a margin, so a second job for the same delivery sends nothing. An event can arrive more than once (after a replay, or when Karta stopped in the middle of a request): drop duplicates by webhook-id.

When a webhook keeps failing

When every request to a webhook has failed for five days, Karta switches it off (enabled: false, disabled_reason: "failing"), logs it, and fails its pending deliveries. Switch it on again with PATCH /api/v2/webhooks/{id} ({"enabled": true}) once your receiver works, then replay the dead letters of the time it was off.

Where requests go

  • The URL is https:// (http:// only on instances whose operator allows it, KARTA_WEBHOOKS_ALLOW_HTTP).
  • A URL may carry a user name and password (https://user:password@hooks.example.com/…), as the providers' webhooks allow: only with https://. Karta keeps them apart from the URL, encrypted, and sends them as Basic authentication (Authorization: Basic …) with every request. The API shows the URL without them and the user name as basic_auth_user, never the password; they are not logged. Giving the URL again replaces them (without them: removes them).
  • Karta resolves the URL's host itself and never connects to private, loopback, link-local, carrier-grade NAT, unique local, NAT64, 6to4, documentation or other special addresses, unless the operator allows that network (KARTA_NET_GUARD_ALLOWED_NETWORKS). It connects to the address it checked, with the URL's host in Host and in TLS, so a second DNS answer cannot send the request elsewhere.
  • A server has at most 20 webhooks.

How long Karta keeps them

Events, their deliveries and their requests are removed 30 days after the event (retention_days), except while a delivery is pending.

Not yet

  • Mailgun's v4 webhooks API and its signing key endpoints; OAuth for SendGrid's webhooks.
  • Events for incoming mail and held messages.