MailCraft
Home Pricing Docs
Integration

Webhooks & Inbound Parse

Receive signed HTTPS callbacks for delivered, bounced, opened and clicked emails, suppressions and inbound mail, and verify the MailCraft-Signature header.

Overview

MailCraft sends an HTTPS POST to your endpoint every time something happens to an email. Create endpoints in Dashboard → Webhooks (account owners only; team members can view them). Each account can have up to 10 endpoints, each subscribed to any subset of event types and optionally limited to one Mail Agent.

Event type When
email.delivered The recipient’s mail server accepted the message (2xx).
email.deferred A delivery attempt got a temporary error; MailCraft will retry.
email.bounced bounce_type: "hard": permanent rejection (5xx or failure DSN). bounce_type: "soft": retries exhausted / message expired, or an asynchronous “delayed” DSN.
email.opened The tracking pixel was loaded (if open tracking is on).
email.clicked A tracked link was clicked (if click tracking is on).
email.suppressed An address was added to your suppression list (hard bounce, complaint, unsubscribe, manual).
inbound.received An email arrived at one of your inbound addresses (see Inbound parse).

Payload

Every request body is one JSON envelope:

{
  "id": "evt_6f1c2a54-3c1e-4a8e-9d55-0f6c3c7b2e11",
  "type": "email.bounced",
  "created_at": "2026-12-05T08:15:02Z",
  "account_id": "0b7d6c1e-5a43-4f7e-8d0a-2f3c1b9e7a10",
  "data": {
    "message_id": "9a3e…",
    "message_id_header": "<20261205081500.9a3e@mail.example.com>",
    "agent_id": "c1d2…",
    "recipient": "someone@example.net",
    "subject": "Your OTP code",
    "status": "bounced",
    "smtp_code": 550,
    "smtp_response": "550 5.1.1 The email account that you tried to reach does not exist",
    "bounce_type": "hard"
  }
}

data fields for email.* events: message_id, message_id_header, agent_id, recipient, subject, status, smtp_code, smtp_response, bounce_type (bounced), url (clicked), ip and user_agent (opened / clicked). Fields that do not apply are omitted. email.suppressed carries recipient, agent_id, status: "suppressed", reason and source. Test events sent from the dashboard have "test": true.

Delivery is at least once and not ordered: use id (also sent as the MailCraft-Event-Id header) to de-duplicate, and created_at to order.

Headers

Header Value
Content-Type application/json
User-Agent MailCraft-Webhooks/1.0
MailCraft-Event-Id evt_<uuid> (same as id)
MailCraft-Event-Type e.g. email.delivered
MailCraft-Signature t=<unix seconds>,v1=<hex signature>

Verifying the signature

Each endpoint has a signing secret of the form whsec_…, shown once when you create it (use Roll secret to get a new one; the old one stops working immediately).

  1. Read the raw request body exactly as received (do not re-serialize the JSON).
  2. Parse t and v1 from MailCraft-Signature.
  3. Compute HMAC-SHA256(key = the whole secret string including "whsec_", message = t + "." + raw_body) and hex-encode it (lowercase).
  4. Compare with v1 in constant time.
  5. Reject the request if |now - t| > 300 seconds (replay protection).

Respond with any 2xx within 10 seconds. Anything else (or a timeout) is retried after 1 min, 5 min, 30 min, 2 h, 6 h and 12 h, then the delivery is marked failed. Redirects are not followed. If an endpoint fails continuously for 3 days, it is disabled and the account owners are emailed. You can resend any delivery from its history with Redeliver.

Node.js (Express)

import crypto from 'node:crypto';
import express from 'express';

const app = express();
const SECRET = process.env.MAILCRAFT_WEBHOOK_SECRET; // whsec_...

app.post('/webhooks/mailcraft', express.raw({ type: 'application/json' }), (req, res) => {
  const header = req.get('MailCraft-Signature') || '';
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=', 2)));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return res.sendStatus(400);

  const expected = crypto.createHmac('sha256', SECRET).update(`${t}.`).update(req.body).digest('hex');
  const given = Buffer.from(parts.v1 || '', 'utf8');
  if (given.length !== expected.length || !crypto.timingSafeEqual(given, Buffer.from(expected, 'utf8'))) {
    return res.sendStatus(400);
  }

  const event = JSON.parse(req.body.toString('utf8'));
  // de-duplicate on event.id, then handle event.type ...
  res.sendStatus(204);
});

PHP

<?php
$secret  = getenv('MAILCRAFT_WEBHOOK_SECRET'); // whsec_...
$payload = file_get_contents('php://input');
$header  = $_SERVER['HTTP_MAILCRAFT_SIGNATURE'] ?? '';

$parts = [];
foreach (explode(',', $header) as $kv) {
    [$k, $v] = array_pad(explode('=', $kv, 2), 2, '');
    $parts[$k] = $v;
}
$t = (int)($parts['t'] ?? 0);
if ($t === 0 || abs(time() - $t) > 300) { http_response_code(400); exit; }

$expected = hash_hmac('sha256', $t . '.' . $payload, $secret);
if (!hash_equals($expected, $parts['v1'] ?? '')) { http_response_code(400); exit; }

$event = json_decode($payload, true);
// de-duplicate on $event['id'], then handle $event['type'] ...
http_response_code(204);

Python (Flask)

import hmac, hashlib, json, os, time
from flask import Flask, request, abort

app = Flask(__name__)
SECRET = os.environ["MAILCRAFT_WEBHOOK_SECRET"].encode()  # whsec_...

@app.post("/webhooks/mailcraft")
def mailcraft_webhook():
    raw = request.get_data()  # raw bytes, before any JSON parsing
    parts = dict(p.split("=", 1) for p in request.headers.get("MailCraft-Signature", "").split(",") if "=" in p)
    t = int(parts.get("t", "0"))
    if not t or abs(time.time() - t) > 300:
        abort(400)
    expected = hmac.new(SECRET, f"{t}.".encode() + raw, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, parts.get("v1", "")):
        abort(400)
    event = json.loads(raw)
    # de-duplicate on event["id"], then handle event["type"] ...
    return "", 204

Inbound parse

Receive email and get it as an inbound.received event. Inbound mail is free (no credits are used). In Webhooks → Inbound email add a receiving address that points at one of your endpoints:

  • Free platform address: <name>@inbound.<platform domain> — works immediately. Plus-addressing is supported: support+ticket-42@… is delivered to the support route.
  • Your own domain: add an MX record on the domain (a dedicated subdomain such as inbound.example.com is recommended), then press Check MX:
inbound.example.com.   MX   10   mx-bounce.<platform domain>.

You can receive every address on the domain (catch-all) or only specific local parts. Unknown recipients are rejected during the SMTP conversation with 550. Messages are limited to 10 MB.

Example data of inbound.received:

{
  "inbound_id": "5c0f…",
  "route_id": "a71e…",
  "from": { "name": "Somchai", "address": "somchai@example.net" },
  "to": [{ "name": "Support", "address": "support@inbound.example.com" }],
  "cc": [],
  "subject": "Order #42",
  "text": "Hello…",
  "html": "<p>Hello…</p>",
  "headers": { "message-id": "<…>", "date": "…", "in-reply-to": "<…>" },
  "attachments": [
    { "filename": "invoice.pdf", "content_type": "application/pdf", "size": 48213, "content_base64": "JVBERi0…" }
  ],
  "envelope": { "from": "somchai@example.net", "to": ["support@inbound.example.com"] },
  "remote_ip": "203.0.113.25",
  "helo": "mail.example.net",
  "dkim": [{ "domain": "example.net", "result": "pass" }],
  "spf": "not_checked",
  "raw_size": 51022
}

Attachment content is included as base64 only when all attachments together are at most 5 MB; otherwise content_base64 is omitted, each attachment has "truncated": true and attachments_truncated is true. The raw message is kept for 7 days.