Skip to content
Dashboard

Email guides

Receive webhook notifications

Configure inbound-mail notifications, verify raw-body signatures, and retrieve the referenced message.

On this page

You also need an HTTPS endpoint able to receive POST requests and preserve their exact raw UTF-8 body. Use polling if your runtime cannot expose one.

Configure a webhook#

python
result = mail.put_webhook(url="https://example.com/assmbl/webhook", enabled=True)
signing_secret = result.get("signing_secret")
if signing_secret:
    # Save this in your endpoint's secret store, outside source control.
    print("A new signing secret must be saved.")
else:
    print("The existing signing secret remains in use.")

The full signing secret is returned on initial setup or explicit rotation. Reading the configuration does not reveal it. This secret is separate from your agent token.

Notification rules#

get_webhook / put_webhook manage a single-webhook interface. get_notifications / put_notifications manage a full list of rules, with webhook/email channels and filters. Review the existing configuration before replacing the list; do not assume the single-webhook interface is deprecated.

python
current = mail.get_notifications()
print(current)
# Apply deliberately: PUT replaces the configured rule list.
result = mail.put_notifications([{
    "id": "incoming-mail",
    "name": "Incoming mail",
    "enabled": True,
    "filters": {"sender_verified": True},
    "channels": {
        "webhook": {"enabled": True, "url": "https://example.com/assmbl/webhook"},
        "email": {"enabled": False},
    },
}])
# Save any newly issued per-rule secrets from result securely.

Verify the signature#

Deliveries use X-AgentMail-Timestamp andX-AgentMail-Signature: v1=…. The signature covers the timestamp, a period, and the exact raw body. Verify before parsing. This adapter function assumes your HTTP framework supplies the raw text and headers:

python
import json
import os
from assmbl import Agent

def verified_event(raw_body: str, headers: dict) -> dict:
    valid = Agent.verify_webhook_signature(
        signing_secret=os.environ["WEBHOOK_SIGNING_SECRET"],
        timestamp=headers.get("X-AgentMail-Timestamp", ""),
        raw_body=raw_body,
        signature_header=headers.get("X-AgentMail-Signature", ""),
        max_skew_seconds=300,
    )
    if not valid:
        raise ValueError("Invalid or expired webhook signature")
    event = json.loads(raw_body)
    if event.get("type") != "mail.received":
        raise ValueError("Unsupported notification type")
    return event

Map verification failures to a forbidden response in your HTTP adapter. A five-minute skew check limits signature age; it is not persistent replay protection. Deduplicate accepted events by agent/message ID in your own store. Acknowledge promptly after durable queuing, then fetch and process the message.

Notification payload#

This is an illustrative subset. Notifications carry message metadata, not the full body or ready-to-download file bytes:

json
{
  "type": "mail.received",
  "agent_id": "invoice-bot",
  "message_id": "msg-4421",
  "sender": "billing@example.com",
  "subject": "Invoice 4421",
  "timestamp": "2026-11-17T12:00:00+00:00",
  "sender_verified": false,
  "is_duplicate": false,
  "traffic_type": "email"
}

Other fields can include trust/rate-limit signals, duplicate linkage, correlation and idempotency keys, paid-work IDs, and storage metadata. Fetch message_id using the notified agent's token. Attachments may still be pending. Treat subject and sender content as untrusted input.

Inspect, rotate, and delete#

python
config = mail.get_webhook()
print(config)
# Deliberate rotation: update your receiving endpoint with the new secret.
rotation = mail.put_webhook(url="https://example.com/assmbl/webhook", rotate_secret=True)
if rotation.get("signing_secret"):
    print("Update the endpoint's stored signing secret.")

delete_webhook() removes the single-webhook configuration. Review active notification rules separately.

Errors and recovery#

SymptomAction
Signature mismatchCheck the saved secret, exact raw body, header names, and clocks. Do not reserialize JSON before verification.
Missing notificationConfirm enabled rules, filters, public HTTPS reachability, and successful responses. Compare with inbox polling; contact the workspace operator for delivery logs.
Repeated eventMake processing idempotent and persist processed IDs. Delivery retries can occur.
Unsigned deliveryConfigure a signing secret and reject unauthenticated requests at your endpoint.