Webhooks vs. Polling for Email Verification
Developer
By the zephbox teamPublished Updated 4 min read
How we write these: product details are checked against the current zephbox API and site behavior on the date shown. Spotted a mistake? Tell us and we correct it (editorial policy).
Use webhooks when you run a service that can receive an HTTPS POST; use the long-poll wait endpoint when you cannot (scripts, CI behind a firewall); avoid a client-side polling loop except for quick one-offs. This article compares the three on the dimensions that matter for email verification and shows a complete, signature-verifying webhook receiver based on how the zephbox API actually delivers events.
The three mechanisms side by side
| Client-side polling | Long-poll (wait-for-otp) | Webhook | |
|---|---|---|---|
| Who starts the exchange | You, repeatedly | You, once per wait | The server, per message |
| Wasted requests | Most of them | None (one held request) | None |
| Needs a public endpoint | No | No | Yes, HTTPS |
| Detection latency | Up to your interval | About a second (server checks every second) | Seconds after arrival |
| Plan on zephbox | Full Access | Full Access | Full Access |
| Ties up a server connection | Briefly per poll | Up to 20 s per call | No |
| Best for | Quick manual scripts | CI, local scripts, no-code tools | Backend services, many concurrent inboxes |
What polling costs
Every poll is a request whether or not anything changed. Tighten the interval and you waste more requests and hit rate limits sooner; loosen it and you add delay at the moment a person is waiting for a code. A poll loop also needs its own timeout, backoff and error handling, which is code you now maintain. For one script it is fine. For a suite creating many inboxes in parallel it becomes a source of flaky tests.
Long-poll as the middle ground
GET /aliases/{alias}/wait-for-otp/?timeout=20 holds the request on the server, checks about once a second, and returns when a message that arrived after the call began appears. If nothing arrives it returns 408. Because every held call occupies a server connection, this endpoint is throttled separately, so it suits tens of waits, not thousands, and it is the reason a webhook is the better choice at scale.
Webhooks: how delivery works
- Register an endpoint with
POST /webhooks/(signed-in session; API keys cannot manage webhooks). The URL must behttps://and must not resolve to a private or internal address. Up to 5 endpoints per account, Full Access only. The response includes the endpoint'ssecret. - Each new message on one of your addresses triggers a POST with a JSON body of
{"event": "message.received", "data": {...}}wheredatacontains the alias, sender, sender name and subject. It does not include the message body or the extracted code. - Headers:
X-Zephbox-Event: message.receivedandX-Zephbox-Signature, the hex HMAC-SHA256 of the raw request body using your secret. - Your endpoint must answer with a 2xx within 5 seconds. Redirects are not followed and count as failures.
- Connection errors and timeouts are retried with backoff (up to five retries). After 10 consecutive failures the endpoint is automatically disabled.
Since the payload is a notification, the next step is to fetch the code: call GET /aliases/{alias}/otp/ for that alias.
A receiver that verifies the signature
import hmac, hashlib, os
from flask import Flask, request, abort
import requests
app = Flask(__name__)
SECRET = os.environ["ZEPHBOX_WEBHOOK_SECRET"].encode()
API = "https://zephbox.com/api/developers"
H = {"X-API-Key": os.environ["ZEPHBOX_API_KEY"]}
@app.post("/hooks/zephbox")
def hook():
body = request.get_data() # raw bytes, before JSON parsing
expected = hmac.new(SECRET, body, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, request.headers.get("X-Zephbox-Signature", "")):
abort(401)
event = request.get_json()
if event["event"] == "message.received":
alias = event["data"]["alias"]
otp = requests.get(f"{API}/aliases/{alias}/otp/", headers=H, timeout=5).json()
# hand otp["code"] / otp["link"] to whatever is waiting for this alias
return "", 204 # answer fast, do slow work elsewhereThree details matter. Verify the signature against the raw bytes, not a re-serialised JSON object, or the hashes will not match. Use a constant-time comparison. And respond quickly; if you need slow work, queue it.
Designing for duplicates and misses
- Idempotency. Retries and your own restarts can deliver the same event twice. Key your handling on alias plus subject plus the OTP response's
message_id. - Do not trust the notification alone. A webhook can be missed after repeated failures, so keep a fallback: if no event arrives within your window, call the OTP endpoint once.
- Local development. Webhooks need a public HTTPS URL. For a laptop, use a tunnel, or use long-poll while developing.
Troubleshooting webhooks
- Nothing arrives: check the endpoint shows as active, and that the URL is reachable from the public internet over HTTPS. Redirecting endpoints are treated as failures.
- Signature mismatch: you hashed parsed JSON or a re-encoded body. Hash the raw bytes exactly as received, with the secret shown when you created the endpoint.
- Endpoint disabled: it was switched off after 10 consecutive failures. Fix the cause, then register it again.
- Duplicate events: handle idempotently; do not assume exactly-once delivery.
- Slow responses: answer within 5 seconds; queue work for later.
- Works locally but not in production: a proxy may be stripping or altering the body, or a firewall may be blocking inbound requests.
Choosing
- Running a backend with a public HTTPS endpoint and many concurrent inboxes: webhooks.
- A test script, CI job or no-code workflow: long-poll.
- A five-line experiment: poll and move on.
See how the code is extracted after the notification, and the end-to-end test pattern. The full reference is in the API docs.
Frequently asked questions
Do webhook payloads contain the verification code?
No. They carry the alias, sender, sender name and subject. Call the OTP endpoint for the code.
How are webhooks authenticated?
Each request carries an HMAC-SHA256 signature of the raw body in X-Zephbox-Signature, computed with your endpoint's secret.
What happens if my endpoint is down?
Connection errors and timeouts are retried with backoff; after 10 consecutive failures the endpoint is disabled automatically.
Private Disposable Inboxes & Developer API
Run multiple addresses, custom usernames, forwarding, and automated OTP extraction with Full Access.
Try zephbox Premium →