Guides
Webhooks
Receive signed events for every email, with automatic retries.
Webhooks send an HTTPS POST to your endpoint whenever something happens to an email.
Add an endpoint
Create an endpoint in the dashboard or with POST /webhooks, then choose the events it should receive.
Events
| Event | When |
|---|---|
email.sent | Accepted by Amazon SES. |
email.delivered | Delivered to the recipient mail server. |
email.bounced | Rejected by the recipient. |
email.complained | Marked as spam. |
email.opened | Opened, when open tracking is on. |
email.clicked | A link was clicked, when click tracking is on. |
email.failed | Could not be sent. |
email.delivery_delayed | Delivery is delayed and still retrying. |
email.received | A message arrived on an inbound route. |
domain.updated | A domain changed verification status. |
contact.created, contact.updated, contact.deleted | A contact changed. |
Verify the signature
Every request carries three headers: nusend-id, nusend-timestamp and nusend-signature. The signature is a hex HMAC-SHA256 of id.timestamp.body using your endpoint secret. Always verify it, and reject old timestamps.
import crypto from "node:crypto";
export function verifyWebhook(rawBody: string, headers: Record<string, string>, secret: string): boolean {
const id = headers["nusend-id"];
const timestamp = headers["nusend-timestamp"];
const signature = headers["nusend-signature"];
if (!id || !timestamp || !signature) return false;
// Reject events older than 5 minutes
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const expected = crypto
.createHmac("sha256", secret)
.update(`${id}.${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(signature);
const b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
}Retries
- Respond with any 2xx status within 10 seconds to acknowledge an event.
- Anything else is retried with exponential backoff for up to about 24 hours.
- An endpoint that keeps failing is disabled and the team owner is notified.
- Every attempt is logged. You can replay a delivery from the dashboard.
Events can arrive more than once. Use the nusend-id header to ignore duplicates.