Webhooks

Get notified on your endpoint when an email arrives, is sent or gets a label. Create a webhook in the app, verify its signature, handle retries.

A webhook lets Maylee tell your endpoint when something happens, instead of polling the API in a loop: cheaper in quota, and without delay. It works with your own server as well as with Zapier, Make or n8n.

Create a webhook

Webhooks are created in the Maylee app, in Account settings, Webhooks, by the owners and admins of the workspace. They cannot be created with an API key: a leaked key must not be able to send your events elsewhere.

  1. Pick what you want to do. Each use case selects the right events: send every new email to a CRM, Zapier, Make or n8n; get notified when a label such as Urgent is applied (to reach Slack or Teams, go through Zapier, Make or n8n); track sent emails; keep a tool in sync with read, starred and deleted emails; get alerted when a mailbox stops synchronizing. Custom lets you choose the events yourself.
  2. Narrow it down if needed. Limit the webhook to some mailboxes, and label.applied to some labels. With no filter, everything is sent.
  3. Paste the URL of your endpoint and save.
  4. Copy the signing secret (whsec_...). It is shown only once. If you lose it, renew it: the old one stops working immediately.
  5. Send a test. Maylee sends a sample event to your endpoint and shows the HTTP code and the response time. Zapier, Make and n8n use this first event to discover the fields.

From the list, you can pause, edit or delete a webhook, and see its last 20 deliveries with their status.

The number of active webhooks depends on the plan: 1 on Free, 5 on Premium, 20 on Expert.

Events

EventFired whendata
email.receivedAn email arrives in an inbox.{ "emailId", "mailboxId", "folderType": "INBOX" }
email.updatedAn email is marked read or unread, starred or unstarred.{ "emailId", "changes": { "isRead": true } } or { "emailId", "changes": { "isStarred": true } }
email.deletedAn email is moved to the trash.{ "emailId", "mailboxId" }
draft.sentAn email is sent from Maylee: the app, the API (POST /drafts/send) or the MCP server. Scheduled sends and automatic replies do not fire it.{ "mailboxId", "messageId", "threadId", "to": ["client@acme.com"], "subject" }
label.appliedA label is added to an email: by a person, through the API or the MCP server, or by an AI label when a new email arrives.{ "emailId", "tagId", "tagName", "isAiLabel" }
mailbox.sync_failedA synchronization attempt fails. deactivated: true means Maylee stopped synchronizing the mailbox until it is reconnected.{ "mailboxId", "error", "failCount", "deactivated" }
  • email.received means a message arrived. It only fires for the inbox: your own sent messages and your drafts never fire it, so an agent does not react to what it just wrote.
  • label.applied fires once per email and label, only when the label was actually added. AI labels fire it when they classify a new email; classifying the emails already there (POST /ai-label-rules/backfill) does not, so that a backfill does not flood your endpoint.
  • Filters apply before sending: a webhook limited to some mailboxes only receives the events of those mailboxes, and a label filter only concerns label.applied.
  • mailbox.sync_failed fires on every failed attempt, each counted in failCount.

Payload

Every delivery is a POST with a JSON body: the event name, when it was emitted, and a data object whose shape depends on the event.

{
  "event": "email.received",
  "createdAt": "2026-08-25T14:32:11.000Z",
  "data": {
    "emailId": "cmemx1a2b3c4d5e6f7g8h9i0",
    "mailboxId": "cmbx1a2b3c4d5e6f7g8h9i0j",
    "folderType": "INBOX"
  }
}

Payloads carry identifiers, not the content of the email. Fetch the email with GET /emails/{emailId}: the content travels over an authenticated channel, and your endpoint does not become a store of personal data by accident.

createdAt is when the event happened: it stays the same when a delivery is retried.

Three headers come with every delivery:

X-Maylee-Event: email.received
X-Maylee-Delivery: cmdl1a2b3c4d5e6f7g8h9i0j
X-Maylee-Signature: t=1787666985,v1=5257a869e7ec...

X-Maylee-Delivery identifies the delivery and stays the same across retries: it is the simplest key to deduplicate on.

A test sent from the app has the same shape, with "test": true next to event, obviously fake ids, and no X-Maylee-Delivery header. Ignore it in production code if you want to.

Verify the signature

Do it on every request. Your endpoint is public: without verification, anyone can send it a fake event.

The signature is an HMAC-SHA256 of the timestamp and the raw body joined by a dot (${t}.${rawBody}), keyed with the webhook's signing secret (whsec_..., used whole, prefix included). Signing the timestamp with the body means a captured delivery cannot be replayed later: reject any timestamp more than 5 minutes away from your clock.

import express from 'express'
import { createHmac, timingSafeEqual } from 'node:crypto'

const TOLERANCE_SECONDS = 300

export function verifyMayleeSignature(secret, rawBody, header) {
  const parts = new Map(
    header.split(',').map((part) => {
      const [key, ...rest] = part.trim().split('=')
      return [key, rest.join('=')]
    })
  )
  const timestamp = Number(parts.get('t'))
  const provided = parts.get('v1')
  if (!Number.isFinite(timestamp) || !provided) return false

  // Reject outside the window BEFORE comparing: an old but valid
  // signature is a replay.
  if (Math.abs(Date.now() / 1000 - timestamp) > TOLERANCE_SECONDS) return false

  const expected = createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex')
  const a = Buffer.from(expected, 'hex')
  const b = Buffer.from(provided, 'hex')

  // Constant-time comparison: `===` would leak where the strings differ.
  return a.length === b.length && timingSafeEqual(a, b)
}

const app = express()

// The raw body: the signature is computed on the exact bytes received.
app.post('/webhooks/maylee', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.get('X-Maylee-Signature') ?? ''
  if (!verifyMayleeSignature(process.env.MAYLEE_WEBHOOK_SECRET, req.body, signature)) {
    return res.status(400).send('Invalid signature')
  }
  const event = JSON.parse(req.body.toString('utf8'))
  res.sendStatus(200) // answer fast, then process in the background
  handleEvent(event)
})

Two classic pitfalls:

  • Sign the raw body, not the result of parsing then serializing it again: the slightest difference in spacing or key order breaks the signature.
  • Never compare signatures with ==. Use a constant-time comparison.

Your endpoint

  • It must use https on port 443, carry no credentials in the URL, and resolve to a public address. Internal addresses (127.0.0.1, 10.0.0.0/8, 169.254.169.254 and the like) and local names (localhost, *.local, *.internal, a name without a dot) are refused.
  • The host name is resolved when you save the webhook, so that a wrong URL is refused right away, and again at every delivery: a record that later points to an internal address is refused at that moment.
  • Redirects are not followed: answer directly from the URL you registered.
  • In development, localhost and private tunnels cannot receive deliveries: use a public receiver or an https tunnel.

Retries

A delivery succeeds when your endpoint answers 2xx within 10 seconds. Anything else is retried, including a 4xx: an endpoint that answers 404 during a deployment gets the delivery once it is back. Five attempts in total:

AttemptDelay after the previous failure
1Immediate
25 minutes
330 minutes
42 hours
56 hours
ThenThe delivery is abandoned.

After three days of continuous failure, the webhook is disabled: an endpoint broken for three days rarely comes back on its own. Deliveries never count against your API quota.

Good practices

  • Answer fast, process later. Return 200 as soon as the request arrives and do the work in the background: taking more than 10 seconds turns the delivery into a failure, and you receive it again.
  • Be idempotent. A 2xx lost on the way causes a retry, so the same event can reach you twice. Deduplicate on the X-Maylee-Delivery header.
  • Do not rely on the order. Retries shift deliveries: an email.updated can arrive before the matching email.received. Read the current state from the API rather than rebuilding it from the sequence of events.

On this page