Webhooks
MailCraft calls your endpoint when mail arrives; when a message is sent, delivered, bounced, complained about or failed; when a draft is submitted, sent or rejected; and when a plan change affects your mail.
Add an endpoint
Endpoints are managed on the console's Webhooks page (members and above). Give an endpoint an https:// (or http://) address and choose the event types it receives, or none for all of them. An organization can have up to 20 endpoints.
The signing secret (whsec_…) is shown once, when you add the endpoint. Rotate secret on the same page issues a new one, also shown once, and the old one stops working at once: deliveries from then on are signed with the new secret. Each endpoint's Deliveries list shows every attempt and its outcome.
The request
Each delivery is a POST with a JSON body, the event's envelope:
{
"id": "evt_…",
"type": "message.received",
"created_at": "2026-11-10T09:30:00.000Z",
"createdAt": "2026-11-10T09:30:00.000Z",
"data": { … }
}
id identifies the event, type is one of the event types below, createdAt is when it happened (ISO 8601, UTC), and data is the event's payload. created_at has the same value and is deprecated (2026-11-20): read createdAt; created_at will be removed on or after 2026-12-21. The event feed, GET /v0/events, returns the same envelopes.
Each request also carries these headers:
User-Agent: MailCraft-Webhooks/1.0 (+https://mailcraft.ntconnect.com/docs/webhooks)
Mailcraft-Event-Id: evt_…
Mailcraft-Delivery-Id: dlv_…
Mailcraft-Delivery-Attempt: 1
Mailcraft-Signature: t=…,v1=…
Mailcraft-Event-Id is the body's id, the same on every delivery of the event. Mailcraft-Delivery-Id names this endpoint's delivery of it, as listed on the Webhooks page. Mailcraft-Delivery-Attempt is this request's attempt number, 1 for the first and counting up on each retry, as the deliveries list shows it. Mailcraft-Signature is described below.
Casing. Webhook payloads (data) are snake_case (message_id, thread_id, inbox_id). REST request and response bodies are camelCase (threadId, inboxId, createdAt). The ids are the same strings in both.
Check the signature
Every delivery is signed in one header:
Mailcraft-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256>
v1 is the HMAC-SHA256 of the string <t>.<body>, the timestamp, a dot and the raw request body, keyed with the endpoint's signing secret (the whole whsec_… string), in lower-case hex. To verify:
- Read the body as raw bytes, before any JSON parsing. A re-serialised body will not match.
- Split the header into
tandv1. - Compute the HMAC of
t, a dot and the raw body, and compare it withv1in constant time. - Reject a timestamp more than a few minutes from your clock, either way. The samples use 5 minutes. The timestamp is inside the signed string, so it cannot be changed without breaking the signature; the window is what stops an old request from being replayed.
Node
import { createHmac, timingSafeEqual } from "node:crypto";
const TOLERANCE_SECONDS = 300;
// rawBody: the request body exactly as received, as a Buffer.
// header: the Mailcraft-Signature header (Node lower-cases it: req.headers["mailcraft-signature"]).
export function verifyMailcraftSignature(secret, header, rawBody, nowSeconds = Math.floor(Date.now() / 1000)) {
const match = /^t=([0-9]+),v1=([0-9a-f]+)$/.exec(header ?? "");
if (!match) return false;
const timestamp = match[1];
const expected = createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest("hex");
const given = Buffer.from(match[2], "utf8");
const wanted = Buffer.from(expected, "utf8");
if (given.length !== wanted.length || !timingSafeEqual(given, wanted)) return false;
return Math.abs(nowSeconds - Number(timestamp)) <= TOLERANCE_SECONDS;
}
Python
The same function, line for line:
import hashlib, hmac, re, time
TOLERANCE_SECONDS = 300
# raw_body: the request body exactly as received, as bytes.
# header: the Mailcraft-Signature header.
def verify_mailcraft_signature(secret, header, raw_body, now_seconds=None):
match = re.fullmatch(r"t=([0-9]+),v1=([0-9a-f]+)", header or "")
if not match: return False
timestamp = match.group(1)
expected = hmac.new(secret.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(match.group(2), expected): return False
if now_seconds is None: now_seconds = int(time.time())
return abs(now_seconds - int(timestamp)) <= TOLERANCE_SECONDS
Answer, retries and duplicates
Answer with a 2xx within 10 seconds. Anything else, including a redirect (redirects are not followed) or a timeout, is a failure, and MailCraft tries again after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 24 hours: seven attempts over about 33 hours. If the last one fails too, the endpoint is disabled; fix it and enable it again on the Webhooks page. Events that happen while an endpoint is disabled are not queued for it; read them from GET /v0/events.
Delivery is at least once: the same event can arrive more than once, for example when your 2xx is lost on the way back. Every delivery of an event carries the same evt_ id, so record the ids you have handled and skip a repeat. Retries mean events can arrive out of order; use createdAt, or the event feed, which is in order.
While an organization's payment is failing, new mail is stored but held, and its message.received is delivered when the mail is released.
Event types
Ignore event types you don't recognise: new ones are added without a version change. Every payload that concerns one inbox carries channel (today always "email").
| Type | When | data fields |
|---|---|---|
message.received | Mail arrived in an inbox. | message_id, thread_id, inbox_id, channel, from, subject, spf, dkim, dmarc. A message that could not be parsed has parse_failed: true and no thread_id, from or subject; its raw MIME is still stored. |
message.sent | A message you sent was handed to the mail provider. | message_id, thread_id, inbox_id, channel |
message.delivered | One recipient's server accepted it (one event per recipient). | as message.sent, plus recipient |
message.bounced | One recipient's address bounced permanently. The address is added to your suppressions. | as message.sent, plus recipient, bounce_type ("Permanent"), detail |
message.complained | One recipient marked it as spam. The address is added to your suppressions. | as message.sent, plus recipient |
message.failed | A message could not be sent. | as message.sent, plus error |
draft.submitted | An agent's or a member's draft now waits for an owner or admin. | draft_id, inbox_id, author_key_id (key_…; null for a member's draft), author_user_id (usr_…; null for an agent's), author_name (the author's name as it was then: an API key's name, or a member's name or, without one, their email; null if neither), subject, recipient_count, channel |
draft.sent | A draft was sent (for a waiting draft, an owner or admin approved it). | draft_id, message_id, edited, approved_by (usr_…: the person who sent a draft they did not write; null when an API key sent it, or when its own author did, such as a member who was made an admin sending their own waiting draft), approved_by_name (that person's name, or their email without one; null with approved_by), channel |
draft.rejected | An owner or admin rejected a draft that waited for approval. | draft_id, note, rejected_by (usr_…), rejected_by_name (that person's name, or their email without one), channel |
plan.hold_started | A payment failed: new mail is stored but held. | held_since |
plan.hold_released | Held mail was released: the payment recovered, or the organization upgraded. | reason ("payment_recovered" or "upgraded"), released_messages; on an upgrade also restored_inbox_ids |
plan.fell_back_to_free | The payment did not recover and the organization moved to Free. | kept_inbox_ids, over_quota_inbox_ids, receiving_stops_at, deleted_at, deletion_is_permanent, released_messages |
plan.kept_inboxes_changed | The owner or an admin changed which inboxes to keep after the move to Free. | as plan.fell_back_to_free |
inbox.receiving_stopped | An inbox over the Free limit stopped receiving mail, 7 days after the move. | inbox_id, channel, address, deleted_at, deletion_is_permanent |
inbox.deleted | An inbox was deleted with its mail: by an owner, admin or permitted API key, or 14 days after a move to Free over its limit. | inbox_id, channel, address, deletion_is_permanent, reason ("deleted" or "payment_lapse") |
Details of the draft events are on Human approval.