Feedback mechanisms: options to be notified when email sending failed #3662
|
I want to be notified (e.g. via Email or in Slack) when email was not sent (e.g. it was held). Except Webhook (that is not compatible with Slack) are there any options? |
Replies: 1 comment 3 replies
|
For held or failed messages, webhooks are the only thing Postal pushes out. The built-in emails only cover a server nearing or exceeding its send limit and a server being suspended, and they go to every user in the organization. Nothing emails you about an individual held, failed or bounced message. The HTTP API can't list held messages either, so the Held tab in the web UI is the only list. The webhook events you want:
Slack answers // postal-slack-relay.mjs (Node 18+, no dependencies)
// POSTAL_URL=https://postal.example.com SLACK_WEBHOOK_URL=https://hooks.slack.com/services/... node postal-slack-relay.mjs
import http from "node:http";
import crypto from "node:crypto";
const { POSTAL_URL, SLACK_WEBHOOK_URL, PORT = 8080 } = process.env;
const EVENTS = ["MessageHeld", "MessageDeliveryFailed", "MessageDelayed", "MessageBounced"];
const jwks = await (await fetch(`${POSTAL_URL}/.well-known/jwks.json`)).json();
const key = crypto.createPublicKey({ key: jwks.keys[0], format: "jwk" });
const esc = (s) => String(s ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
http.createServer((req, res) => {
const chunks = [];
req.on("data", (c) => chunks.push(c));
req.on("end", async () => {
try {
const body = Buffer.concat(chunks);
const sig = Buffer.from(req.headers["x-postal-signature-256"] || "", "base64");
if (!crypto.verify("sha256", body, key, sig)) return res.writeHead(401).end();
const { event, payload } = JSON.parse(body);
if (EVENTS.includes(event)) {
const m = payload.message || payload.original_message; // MessageBounced uses original_message
const why = [payload.details, payload.output].filter(Boolean).join("\n") || `Bounce received (bounce message id ${payload.bounce?.id})`;
const text = `*${event}*: "${esc(m.subject)}" from ${esc(m.from)} to ${esc(m.to)} (id ${m.id})\n${esc(why)}`;
const r = await fetch(SLACK_WEBHOOK_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text }) });
if (!r.ok) throw new Error(`Slack returned ${r.status}`);
}
res.writeHead(200).end("ok");
} catch (e) {
console.error(e);
res.writeHead(500).end(); // non-2xx makes Postal retry
}
});
}).listen(PORT);Then point a webhook on the server at the relay and select only those four events. Notes:
|
For held or failed messages, webhooks are the only thing Postal pushes out. The built-in emails only cover a server nearing or exceeding its send limit and a server being suspended, and they go to every user in the organization. Nothing emails you about an individual held, failed or bounced message. The HTTP API can't list held messages either, so the Held tab in the web UI is the only list.
The webhook events you want:
MessageHeld: send limit reached, recipient on the suppression list, credential set to hold, server in development mode or suspendedMessageDeliveryFailed: hard fail, e.g. a 5xx from the remote server, spam threshold, max attempts reachedMessageDelayed: soft fail. It fire…