Skip to main content

Webhooks

Webhooks let your application react to email events in real time.

Supported events

EventFired when
inbound_emailA new inbound message arrives.
delivery_statusOutbound message delivery status changes.
bounceA delivery attempt bounces.
complaintA recipient marks the message as spam.
domain_verifiedA domain's DNS records are fully verified.
mailbox_createdA new mailbox is created.
migration_completeA mail migration finishes.
rate_limit_warningYour account is approaching a rate limit.
allSubscribe to every event.

Create a webhook

curl -X POST https://api.purpletoadmail.com/api/v1/webhooks \
-H "Authorization: Bearer pt_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"url": "https://yourapp.com/webhooks/purpletoad",
"events": ["delivery_status", "bounce", "inbound_email"]
}'

The API generates a secret for you and returns it once in the response. Store it securely — it is used to verify webhook signatures.

Signature verification

Every webhook request includes an X-PurpleToad-Signature header in the format sha256=<digest>. Compute an HMAC-SHA256 of the raw body using your webhook secret and compare the prefixed value.

import hmac, hashlib

digest = hmac.new(secret.encode(), body.encode(), hashlib.sha256).hexdigest()
signature_header = request.headers['X-PurpleToad-Signature']
expected = f"sha256={digest}"
assert hmac.compare_digest(expected, signature_header)

Webhook deliveries also include X-PurpleToad-Event, X-Event-ID, and X-PurpleToad-Timestamp headers.