saci.cc webhooks: get every email as a POST
On the Pro and Team plans, saci.cc can tell you when an email arrives, instead of you asking. Each email that reaches one of your account's inboxes becomes a POST to your URL, with the sender, subject, links and verification code already pulled out. This post covers when that's worth it, how to check the POST really came from saci.cc, and an example that sends codes to a Slack channel.
Waiting with the API or getting a webhook
For an automated test, waiting with the API is usually the best way. The test creates the inbox, does the action and calls GET /addresses/{address}/emails?wait=25, and the API holds the response until the email arrives. No server needed, and it works in CI, where nothing is reachable from the internet. The saci.cc npm package does this for you with waitForCode().
A webhook is better when whoever needs the email isn't the process that did the action:
- Manual QA. Someone tests sign-up on their phone and the code shows up in a Slack or Teams channel, without opening saci.cc.
- Monitoring. A scheduled job signs up on production every hour, and your server checks that the email arrived and how long it took.
- Volume. A suite with hundreds of simultaneous tests keeps hundreds of connections open waiting. With a webhook, your server gets everything and the tests read from a database or a queue.
- Archiving. Emails are deleted about a day after they arrive. If you want to keep what your app sent, the webhook delivers each one as soon as it arrives.
Setting it up
On your account page, open the Webhook tab, enter the URL and save. The URL must be HTTPS and on the public internet: localhost and private IPs are refused. When you save, the secret shows up, starting with whsec_. Keep it on your server, for example as SACI_WEBHOOK_SECRET.
The Send a test button sends a POST with "event": "test" and made-up values, so you can check the URL and the signature before real emails come in. The same tab shows the result of the last delivery.
On the Team plan, the webhook belongs to the account: emails to inboxes created by anyone on the team go to the same URL.
What arrives
{
"event": "email.received",
"address": "qa-checkout@saci.cc",
"messageId": "0100019a...",
"from": "Loja <no-reply@loja.example>",
"subject": "Seu código de acesso",
"receivedAt": "2026-11-22T14:03:11.402Z",
"verificationCode": "481920",
"verificationLink": null,
"links": ["https://loja.example/ajuda"]
}verificationCode and verificationLink are null when the email has no code or confirmation link. The email body isn't in the POST; if you need the HTML or text, call GET /addresses/{address}/emails/{messageId} with your key.
Checking the signature
Anyone who finds your URL can POST to it. That's why each delivery comes with a Saci-Signature: t=<seconds>,v1=<hmac> header, where v1 is an HMAC-SHA256 of "<t>.<body>" made with your secret. Three things to get right:
- Compute the HMAC over the body exactly as it arrived, before
JSON.parse. Reformatting the JSON changes the bytes and the signature won't match. - Compare with
timingSafeEqual, not===. - Refuse deliveries whose
tis more than 5 minutes old, so a captured POST can't be replayed.
An example: codes in Slack
This handler uses the standard Request and Response API, so it works as a Next.js route handler, on Bun, on Deno or in a Cloudflare Worker with Node compatibility:
import { createHmac, timingSafeEqual } from "node:crypto";
const SECRET = process.env.SACI_WEBHOOK_SECRET!; // whsec_...
const SLACK = process.env.SLACK_WEBHOOK_URL!;
const seen = new Set<string>();
// Checks the POST came from saci.cc
function verify(header: string, body: string): boolean {
const { t, v1 } = Object.fromEntries(header.split(",").map((part) => part.split("=")));
// Refuses deliveries signed more than 5 minutes ago
if (!t || !v1 || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = createHmac("sha256", SECRET).update(`${t}.${body}`).digest("hex");
return v1.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}
export async function POST(request: Request): Promise<Response> {
// The body as it arrived, before reading the JSON
const body = await request.text();
if (!verify(request.headers.get("saci-signature") ?? "", body)) return new Response("bad signature", { status: 400 });
const email = JSON.parse(body);
// If the first attempt was slow, the same email can arrive twice
if (email.event !== "email.received" || seen.has(email.messageId)) return new Response("ok");
seen.add(email.messageId);
const detail = email.verificationCode ?? email.verificationLink ?? email.subject;
// A Slack incoming webhook
await fetch(SLACK, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: `${email.address}: ${detail}` }),
signal: AbortSignal.timeout(3000),
}).catch(() => {});
// Answer quickly: saci.cc waits 5 seconds at most
return new Response("ok");
}The in-memory Set is fine for an example; on a server with several instances, keep the messageId in a database.
How delivery works
- Your URL has 5 seconds to answer with a 2xx status. If it fails or is slow, saci.cc tries once more, and that's it. Do heavy work after answering, or in a queue.
- Redirects aren't followed: use the final URL.
- Since there can be a second attempt, the same
messageIdcan arrive twice. Ignore repeats. - If your webhook is down, the emails stay in the inbox for about a day and can be read through the API.
In short
- For tests in CI, wait with the API or the npm package. For manual QA, monitoring, volume and archiving, use the webhook.
- Set the URL in the Webhook tab of your account and keep the
whsec_secret. - Check
Saci-Signatureover the raw body, compare in constant time and refuse old deliveries. - Answer within 5 seconds and ignore repeated
messageIds.
Webhooks are part of the Pro and Team plans. The full format is in the docs.