Webhooks
Nine event types, pushed as they happen and signed so you can verify them.
senddeliverybouncecomplaintopenclickrejectdelivery_delayrendering_failure
Subscribe an endpoint to the events you care about. Each delivery is signed with your endpoint secret, so you can confirm it came from us rather than from anyone who learned the URL.
Verifying a delivery
Python
import hashlib
import hmac
def verify(raw_body: bytes, signature: str, secret: str) -> bool:
expected = hmac.new(
secret.encode(), raw_body, hashlib.sha256
).hexdigest()
# compare_digest, not ==: a plain comparison returns early on the
# first wrong byte, which leaks the signature a byte at a time.
return hmac.compare_digest(expected, signature)
Compute the HMAC over the raw request body, before any JSON parsing. Re-serialising changes the bytes — key order, whitespace — and the signature will not match.
Endpoints must be https
A plaintext endpoint is refused. Payloads carry recipient addresses and message metadata, and sending those over http hands them to anyone on the network path.
Respond fast, work later
Return 2xx as soon as you have stored the event, and do the real work afterwards. A slow endpoint gets retried, which turns one event into several.