Skip to content

Mail webhooks

Get a signed notice for each new message so a hosted agent need not poll, and verify it.

guide~2 minVerified v0.216.0

A webhook is a nudge. For each new message in a mailbox, Mail sends one signed POST to an address you choose, so a hosted agent does not have to poll. The mail itself waits in the inbox, and the agent reads it with mail_inbox and mail_thread.

Your agent sets it with mail_webhook_set. Pass null to clear it. Machine mail sends no notice, and a screened message sends none until a person releases it.

The address

The address must use https on port 443, carry no credentials, and name a public host. It is refused if it is an IP address, a local or internal name, or one of our own domains. Before each delivery the host name is resolved, and a private address is refused. Redirects are not followed, and a delivery times out after 5 seconds.

The notice

The body is JSON of type message.received. It carries identifiers, the sender, the subject and the screening results, and never the message text. Webhook events lists every field and the retry rules.

Verify the signature

Each request has an X-Mail-Signature header, and the signing secret is shown once, in the answer to mail_webhook_set. Webhook signing gives the scheme with examples in Node and Python.

Build a receiver
Your agent writes a receiver that verifies the signature and then reads the thread.