Guide

Postmark webhooks: receive bounce and delivery events locally

Postmark webhooks post a JSON record to your URL when an email is delivered, bounces, is opened or is marked as spam, and when an inbound email arrives. Postmark needs a public URL to send them to. Here is how to add a webhook to a message stream, protect it and test each record type against a local handler.

All docs

Get a public URL for Postmark webhooks#

Postmark can't deliver to localhost. An OtterKit webhook endpoint gives you a public HTTPS URL that answers Postmark around the clock and keeps every request, so nothing is lost while your laptop is closed or your handler is half written:

Terminal
npx otterkit login
npx otterkit webhook --daemon --subdomain postmark-dev
#   https://postmark-dev.otterkit.app

The name is reserved to your account, so the URL stays the same every time you start it. An endpoint costs $0.01 per hour while it is live and never more than $3 in any 30 days, and new accounts get 10 free credits. To look at a payload before you sign up, the try page gives you a live URL in the browser with no account.

Register the URL in Postmark#

  1. In Postmark, open the server, pick the message stream, and go to its Webhooks tab. Click Add webhook.
  2. Paste the endpoint URL and tick the events: delivery, bounce, spam complaint, open, link click or subscription change.
  3. Optionally add Basic auth credentials or custom headers, then save. Inbound email is set separately, on the inbound stream's settings.

Use https://postmark-dev.otterkit.app as the URL. Add a path if your handler expects one, such as https://postmark-dev.otterkit.app/webhooks/postmark: the endpoint accepts any path and records it.

Protect a Postmark webhook#

Postmark does not sign webhooks. Protect the URL with HTTP Basic auth credentials or a custom header holding a secret, both set on the webhook, and have your handler check them on every request. Always use an HTTPS URL.

Every record has a RecordType field, such as Delivery, Bounce or SpamComplaint, and a MessageID that ties it to the email you sent.

There is nothing to verify cryptographically. The captured request shows the Authorization header and any custom headers exactly as Postmark sent them, so you can confirm your settings before writing the check.

Send a test event#

On the webhook, click Send test and choose a record type. Postmark posts an example of that type.

Then watch it land, or wait for it in a script:

Terminal
# Follow requests as they arrive, with headers and bodies
npx otterkit inspect postmark-dev --follow

# Or block until the next POST, then print it as JSON
npx otterkit await postmark-dev --method POST --count 1 --timeout 120s --json

Replay Postmark events into your local handler#

Once an event is captured you can send it to your handler as often as you like, with the original headers and body, without asking Postmark to fire it again:

Terminal
# Send the latest captured event to a server on port 3000
npx otterkit replay postmark-dev --target 127.0.0.1:3000

# Or a specific one (1 is the oldest, -1 the latest)
npx otterkit replay postmark-dev --index 3 --target 127.0.0.1:3000

Replays cost nothing and are added to the capture log with your handler's response next to them. If you would rather have events delivered live while you work, expose the handler with a tunnel instead and register the tunnel URL.

Retries, timeouts and duplicates#

  • Postmark treats any 2xx as success and retries other responses on a schedule that depends on the record type. A 403 tells it to stop retrying.
  • Open and click events can be frequent. Subscribe only to the record types you act on.

To see how your code copes when a delivery fails, the HTTP status codes guide has URLs that return any status on demand.

Questions about Postmark webhooks#

Does Postmark sign its webhooks?#

No. Use Basic auth or a secret header, and restrict by Postmark's published IP addresses if you need more.

Is the inbound webhook the same as the others?#

It is configured separately and its body is the parsed email: sender, recipients, subject, text and HTML bodies, and attachments.

Why am I not receiving events?#

Webhooks belong to one message stream. Check the webhook is on the stream your emails actually go out on.

Other providers#