Webhooks
Sendfern sends a signed POST request to your endpoint when something happens to an email, a contact or your account. Use webhooks to record deliveries, stop mailing addresses that bounce, and react to unsubscribes without polling.
Create an endpoint
Add an endpoint under Webhooks in the dashboard, or with the API. The response includes the signing secret (whsec_...). It is shown only this once, so store it now, for example in SENDFERN_WEBHOOK_SECRET. If you lose it, delete the endpoint and create a new one.
POST/v1/webhooks
curl https://api.sendfern.com/v1/webhooks \
-H "Authorization: Bearer $SENDFERN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://acme.com/webhooks/sendfern",
"events": ["email.delivered", "email.bounced", "email.complained"]
}'{
"id": "wh_6Pq3nLx8VmK2cR5tWz9YbF",
"url": "https://acme.com/webhooks/sendfern",
"events": ["email.delivered", "email.bounced", "email.complained"],
"enabled": true,
"secret": "whsec_kV9pX2...",
"created_at": "2026-11-28T10:19:04Z"
}Body
urlstringrequired- Where Sendfern sends events. Must be a public
https://address; see Endpoint URLs. eventsstring[]- The event types to receive. Leave it out or send
[]to get every event, including types added later. An unknown type is 400. enabledboolean- Defaults to
true. A disabled endpoint gets no events.
GET /v1/webhooks lists your endpoints, and GET, PATCH and DELETE on /v1/webhooks/{id} read, change and remove one. The secret is never returned again.
Endpoint URLs
The URL must start with https://. It must also resolve to a public internet address: Sendfern will not connect to localhost, private networks (such as 10.x or 192.168.x), link-local or other reserved addresses, and checks the address it actually connects to on every request. A delivery to such an address fails straight away with URL is not a public https address and is not retried. Redirects are not followed, so point the endpoint at the final URL. To receive events on your own machine during development, use a tunnelling service that gives you a public https URL.
Events
Every request carries one event. All email.* events fire for emails sent with POST /v1/emails and for each recipient's email of a broadcast. See Email lifecycle for how events move an email's status.
| Event | When it fires | Extra data fields |
|---|---|---|
email.sent | Sendfern handed the email to the mail servers. Once per email. | recipient is empty. |
email.delivered | The recipient's mail server accepted the email. Once per recipient. | The common fields only. |
email.delivery_delayed | The recipient's server is not accepting the email yet. Delivery is still being tried. | delay_type |
email.bounced | The recipient's server rejected the email. A permanent bounce adds the address to your suppression list. | bounce_type (for example Permanent), bounce_subtype, diagnostic |
email.complained | The recipient marked the email as spam. The address is added to your suppression list. | feedback_type |
email.opened | The recipient opened the email. Needs open tracking. Can fire more than once. | user_agent; recipient is empty. |
email.clicked | The recipient clicked a link. Needs click tracking. Can fire more than once. | link, user_agent; recipient is empty. |
email.failed | The email could not be sent, for example because the account is not active or the content was rejected. | reason |
email.suppressed | A recipient was skipped because the address is on your suppression list. | reason |
contact.unsubscribed | A contact unsubscribed with the link in a broadcast email. | Not the common fields: contact_id, email, audience_id. Always "mode": "live". |
account.paused | Live sending was paused for your account, for example because the bounce or complaint rate got too high. | Not the common fields: only reason. Always "mode": "live". |
Payload
{
"id": "whevt_4Hn7qVx2LmP8cK3tRz5YbW",
"type": "email.delivered",
"mode": "live",
"created_at": "2026-11-28T10:19:06.512034+00:00",
"data": {
"email_id": "em_VNqV5JEIqYYeYbZRhbPrJ6",
"from": "Acme <hello@acme.com>",
"to": ["user@example.com"],
"subject": "Welcome to Acme",
"recipient": "user@example.com",
"tags": {"type": "welcome"},
"broadcast_id": null
}
}idstring- The event id (
whevt_...). Use it to skip duplicates. typestring- One of the event types above.
modestringliveortest: the mode of the email the event is about.created_atstring- When the event was created, ISO 8601 in UTC.
dataobject- For
email.*events:email_id,from,to,subject,recipient(the address the event is about, or empty),tagsandbroadcast_id(nullfor emails not sent by a broadcast), plus the extra fields in the table.contact.unsubscribedandaccount.pausedhave their owndata.
Verify the signature
Anyone can POST to your URL, so check every request before you trust it. Each one has an X-Sendfern-Signature header:
X-Sendfern-Signature: t=1795947546,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
t is the time the request was signed, in Unix seconds. v1 is the hex HMAC-SHA256 of t, a dot, and the raw request body, keyed with your endpoint's full secret (including whsec_). The SDKs do the whole check for you:
import express from "express";
import { verifyWebhook } from "sendfern";
const app = express();
// Keep the raw body: the signature covers the exact bytes Sendfern sent.
app.post("/webhooks/sendfern", express.raw({ type: "application/json" }), (req, res) => {
const rawBody = req.body.toString("utf8");
const header = req.headers["x-sendfern-signature"];
if (!verifyWebhook(process.env.SENDFERN_WEBHOOK_SECRET, header, rawBody)) {
return res.status(400).send("Bad signature");
}
const event = JSON.parse(rawBody);
// Hand the work to a queue, then answer quickly.
res.sendStatus(200);
});verifyWebhook and verify_webhook return false for a missing or malformed header, a wrong signature, or a timestamp more than 5 minutes from now. Change the window with toleranceSeconds (Node.js) or tolerance_seconds (Python).
Verify without the SDK
- Split the header on
,and each part on the first=to gettandv1. - Compute HMAC-SHA256 of the string
${t}.${rawBody}with your secret as the key, as lowercase hex. - Compare it with
v1using a constant-time comparison. - Reject the request if
tis more than a few minutes from your clock. This stops someone replaying an old request they captured. Every attempt is signed afresh, so retries still pass.
The samples below do steps 1 to 3; add the timestamp check to them.
import crypto from "node:crypto";
// rawBody: the exact request body as received, before JSON parsing.
export function isValid(secret, header, rawBody) {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(parts.v1 ?? "");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}import hashlib, hmac
def is_valid(secret, header, raw_body): # raw_body: the exact bytes received, decoded
parts = dict(p.split("=", 1) for p in header.split(","))
expected = hmac.new(secret.encode(), f"{parts['t']}.{raw_body}".encode(), hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Respond and retries
Answer with any 2xx status within 10 seconds. Anything else counts as a failed attempt: another status code (including a 3xx redirect), a timeout, or a connection error. Do slow work after you answer, for example by putting the event on a queue.
A failed attempt is tried again, up to 6 attempts in all:
| Attempt | After the previous one |
|---|---|
| 1 | Right away |
| 2 | 30 seconds |
| 3 | 2 minutes |
| 4 | 8 minutes |
| 5 | 32 minutes |
| 6 | About 2 hours |
After the sixth failed attempt the delivery is marked failed. You can retry it yourself from the delivery log.
Automatic disabling
If 20 deliveries in a row fail (each after all its attempts), Sendfern disables the endpoint: enabled becomes false, it gets no new events, and deliveries still waiting for a retry stop. Any successful delivery resets the count. Test events never count. When you have fixed your endpoint, enable it again in the dashboard or with the API, which also resets the count. Events from while it was disabled are not sent.
curl -X PATCH https://api.sendfern.com/v1/webhooks/wh_6Pq3nLx8VmK2cR5tWz9YbF \
-H "Authorization: Bearer $SENDFERN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"enabled": true}'Delivery log, retry and test
Every event sent to an endpoint is a delivery. The dashboard shows them on the endpoint's page, and the API has the same tools:
GET /v1/webhooks/{id}/deliverieslists deliveries, newest first, with their status (pending,succeededorfailed), attempts, last response code and error, and the payload.POST /v1/webhooks/{id}/deliveries/{delivery_id}/retryqueues one more attempt for afaileddelivery. Any other status is 400not_retryable, and a disabled endpoint is 400endpoint_disabled.POST /v1/webhooks/{id}/testsends a sampleemail.deliveredevent right away and answers 201 with the delivery, so you can see your endpoint's response. It is signed like a real event, withemail_id: "em_test". It is tried once, ignores the endpoint's event list, works on a disabled endpoint, and hastest: true.
# The delivery log for an endpoint
curl https://api.sendfern.com/v1/webhooks/wh_6Pq3nLx8VmK2cR5tWz9YbF/deliveries \
-H "Authorization: Bearer $SENDFERN_API_KEY"
# Try a failed delivery once more
curl -X POST https://api.sendfern.com/v1/webhooks/wh_6Pq3nLx8VmK2cR5tWz9YbF/deliveries/whd_9Tm4kQx7LpV2cN8rWz3YbJ/retry \
-H "Authorization: Bearer $SENDFERN_API_KEY"
# Send a sample event now
curl -X POST https://api.sendfern.com/v1/webhooks/wh_6Pq3nLx8VmK2cR5tWz9YbF/test \
-H "Authorization: Bearer $SENDFERN_API_KEY"{
"id": "whd_9Tm4kQx7LpV2cN8rWz3YbJ",
"event_type": "email.delivered",
"status": "failed",
"attempts": 6,
"response_code": 503,
"last_error": "HTTP 503",
"payload": {"id": "whevt_4Hn7qVx2LmP8cK3tRz5YbW", "type": "email.delivered", ...},
"test": false,
"created_at": "2026-11-28T10:19:06Z"
}Duplicates and ordering
The same event can reach you more than once, for example when your endpoint handled it but answered too late. A retry sends the same payload with the same id, so store the ids you have handled and skip repeats.
Events can also arrive out of order: a retried email.delivered can land after an email.opened. Do not assume an order. Use created_at, or fetch the email with GET /v1/emails/{id} when you need its current status.
Test mode
Endpoints are shared between live and test mode, so the same endpoint gets events for test emails too, with "mode": "test". Simulated outcomes (email.delivered, email.bounced, email.complained) also have simulated: true in data. Check mode before you act on an event, so test traffic never changes live records. Test keys can read endpoints and send test events, but creating, changing or deleting an endpoint needs a live key. See Test mode.
Next steps
See what each event means for an email in Email lifecycle, and how bounces and complaints block addresses in Suppressions. Every webhook endpoint is in the API reference.