Verify JMSURF Mail webhook signatures in Node.js, PHP and Python
Anyone can POST to a public URL. The signature header proves a webhook really came from JMSURF Mail and was not changed on the way. This guide shows the check in three languages and what to do with each event.
How the signature is built
Each webhook request has a header like X-JMSURF-Signature: t=1763884437,v1=5f0c….
tis the Unix time the request was signed.v1is the hex HMAC-SHA256 of the stringt + "." + raw request body, keyed with your endpoint's webhook secret (shown when you create the endpoint in Webhooks).
To verify: split the header, compute the same HMAC over the exact raw body you received, compare in constant time, and reject anything older than five minutes to stop replays.
Node.js
import crypto from "node:crypto";
export function verifyJmsurf(rawBody, header, secret) {
const { t, v1 } = Object.fromEntries((header || "").split(",").map((p) => p.split("=")));
if (!t || !v1) return false;
const expected = crypto.createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
return fresh && v1.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}PHP
<?php
$raw = file_get_contents("php://input");
$header = $_SERVER["HTTP_X_JMSURF_SIGNATURE"] ?? "";
parse_str(str_replace(",", "&", $header), $p);
$expected = hash_hmac("sha256", ($p["t"] ?? "") . "." . $raw, getenv("JMSURF_WEBHOOK_SECRET"));
$fresh = abs(time() - (int)($p["t"] ?? 0)) < 300;
if (!$fresh || !hash_equals($expected, $p["v1"] ?? "")) {
http_response_code(401);
exit;
}
$event = json_decode($raw, true);
// $event["type"], $event["data"]["id"], $event["data"]["recipient"]
http_response_code(200);Python
import hmac, hashlib, time
def verify_jmsurf(raw_body: bytes, header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in (header or "").split(",") if "=" in p)
t, v1 = parts.get("t", "0"), parts.get("v1", "")
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return abs(time.time() - int(t)) < 300 and hmac.compare_digest(v1, expected)The body you receive
{ "type": "email.bounced", "created_at": "2026-11-23T09:13:57Z",
"data": { "id": "4f1c2a3e-…", "recipient": "[email protected]", "reason": "…" } }| type | What to do |
|---|---|
| email.delivered | Mark the message delivered in your system. |
| email.bounced | The address is already suppressed by JMSURF Mail. Ask the customer to update it. |
| email.complained | The person marked you as spam and is suppressed. Stop non-essential email to them. |
| email.opened / email.clicked | Optional analytics (data.link holds the clicked URL). |
| email.failed | Not sent at all; data.error says why. Alert your team. |
Good habits
- Answer with a 2xx within 10 seconds and do slow work afterwards (a queue). Failed deliveries are retried 3 times.
- Make handlers idempotent: the same event can arrive more than once after a retry.
- Use the Send test button in Webhooks to check your endpoint, and watch the last status shown there.
- Your endpoint must be a public https address; private and internal addresses are refused.
Send your first email today
Free plan with 100 emails a month, no card needed. Questions? WhatsApp or call +254 712 504 593, or email [email protected].