Skip to main content

Developer API for automated signups

See the API

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 pollingLong-poll (wait-for-otp)Webhook
Who starts the exchangeYou, repeatedlyYou, once per waitThe server, per message
Wasted requestsMost of themNone (one held request)None
Needs a public endpointNoNoYes, HTTPS
Detection latencyUp to your intervalAbout a second (server checks every second)Seconds after arrival
Plan on zephboxFull AccessFull AccessFull Access
Ties up a server connectionBriefly per pollUp to 20 s per callNo
Best forQuick manual scriptsCI, local scripts, no-code toolsBackend 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

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 elsewhere

Three 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

Troubleshooting webhooks

Choosing

  1. Running a backend with a public HTTPS endpoint and many concurrent inboxes: webhooks.
  2. A test script, CI job or no-code workflow: long-poll.
  3. 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 →

Related guides

← Generate a temporary email now
zephboxDeveloper API for automated signups
Learn more about the zephbox developer API