Skip to content

Webhooks ​

Receive real-time notifications when email events occur — deliveries, bounces, opens, clicks, and more. Subscribe your endpoint, and the platform pushes events to you as they happen.

All examples assume you've set the API key in the constructor. For multi-tenant usage, pass { apiKey } as the last argument to any method. See Configuration.

Create Webhook ​

ts
const { webhook, secret } = await outbound.webhooks.create({
  url: 'https://myapp.com/webhooks/outbound',
  events: ['delivery', 'bounce', 'complaint', 'open', 'click'],
  retryInterval: 300,
  maxRetries: 3,
  retryStrategy: 'exponential',
});

// ⚠️ Store `secret` securely — it's only returned once!
console.log(webhook.id);  // 'uuid'
console.log(secret);      // '64-char hex string'

Parameters ​

FieldTypeRequiredDescription
urlstringYesHTTPS endpoint to receive events
eventsWebhookEvent[]YesEvent types to subscribe to (see table below)
retryIntervalnumberNoSeconds between retries. Min 30, max 86400 (24 hours). Default 300 (5 minutes)
maxRetriesnumberNoMax retry attempts. Between 0 and 10. Default 3
retryStrategy'exponential' | 'linear'NoBack-off mode. exponential (default) doubles the wait after each failed attempt; linear waits a flat retryInterval every time

Retry Constraints

  • retryInterval must be an integer between 30 seconds and 86,400 seconds (24 hours). The bound applies to the configured base interval, not to the computed exponential waits.
  • maxRetries must be an integer between 0 and 10.
  • retryStrategy must be 'exponential' or 'linear'.

The fields are independent. With linear, the total retry span is retryInterval × maxRetries; with exponential, it is retryInterval × (2^maxRetries − 1), and individual waits are not capped: maxRetries alone bounds the ladder. Violating any bound returns a 400 Bad Request.

Available Events ​

EventDescription
sendEmail accepted by AWS SES
deliveryEmail delivered to recipient's mailbox
bounceEmail bounced (hard or soft)
complaintRecipient reported as spam
openRecipient opened the email
clickRecipient clicked a tracked link
rejectEmail rejected by SES before sending
rendering_failureTemplate rendering failed
droppedRecipient was not attempted (e.g. invalid recipient address caught pre-send). Carries data.dropped.reason. Replaces the former failed event.
replyA person wrote in a conversation started by an email sent with captureReplies: true: the recipient, someone they forwarded it to, or your own team. See Conversation Events
auto_replyAn automatic reply, bounce notice or read receipt arrived for an email sent with captureReplies: true
inboundAn email was delivered to one of your mailboxes. See Inbound Events

Response ​

ts
{
  webhook: {
    id: '550e8400-e29b-41d4-a716-446655440000',
    url: 'https://myapp.com/webhooks/outbound',
    events: ['delivery', 'bounce', 'complaint', 'open', 'click'],
    retry_interval: 300,
    max_retries: 3,
    retry_strategy: 'exponential',
    active: true,
    status: 'active'
  },
  secret: 'a1b2c3d4e5f6...64-char-hex-string',
  warning: 'Store this secret securely. It will not be shown again.'
}
FieldDescription
webhookThe created webhook object
secretHMAC signing secret — only returned on creation. Store it securely.
warningReminder to save the secret

Possible Errors ​

ErrorStatusCause
BadRequestError400Missing url or events, invalid event type, retry constraint exceeded
AuthenticationError401Invalid or missing API key

List Webhooks ​

Retrieve all webhooks registered for your tenant.

ts
const { webhooks } = await outbound.webhooks.list();

for (const wh of webhooks) {
  console.log(`${wh.url} — ${wh.status} — events: ${wh.events.join(', ')}`);
}

Response ​

ts
{
  webhooks: [
    {
      id: '550e8400-e29b-41d4-a716-446655440000',
      url: 'https://myapp.com/webhooks/outbound',
      events: ['delivery', 'bounce', 'complaint', 'open', 'click'],
      retry_interval: 300,
      max_retries: 3,
      retry_strategy: 'exponential',
      active: true,
      status: 'active',
      created_at: '2026-03-08T10:00:00.000Z'
    }
  ]
}

Webhook Status Reference ​

StatusDescription
activeWebhook is enabled and receiving events
defectiveToo many consecutive delivery failures — webhook is auto-disabled

TIP

A defective webhook can be re-enabled by updating it with active: true. This resets the status back to active.


Update Webhook ​

Only pass the fields you want to change:

ts
const { webhook } = await outbound.webhooks.update('webhook-uuid', {
  events: ['delivery', 'bounce'],
  active: true,
});

Parameters ​

All fields are optional:

FieldTypeDescription
urlstringNew HTTPS endpoint
eventsWebhookEvent[]Updated event list
activebooleanEnable or disable the webhook
retryIntervalnumberSeconds between retries. Min 30, max 86400 (24 hours)
maxRetriesnumberMax retry attempts. Between 0 and 10
retryStrategy'exponential' | 'linear'Back-off mode: exponential doubles the wait each attempt, linear waits retryInterval every time

Response ​

ts
{
  message: 'Webhook updated',
  webhook: {
    id: '550e8400-e29b-41d4-a716-446655440000',
    url: 'https://myapp.com/webhooks/outbound',
    events: ['delivery', 'bounce'],
    retry_interval: 300,
    max_retries: 3,
    retry_strategy: 'exponential',
    active: true,
    status: 'active',
    created_at: '2026-03-08T10:00:00.000Z'
  }
}

Re-enable a Defective Webhook ​

ts
// If a webhook was auto-disabled due to failures, reactivate it:
await outbound.webhooks.update('webhook-uuid', { active: true });
// status resets from 'defective' → 'active'

Possible Errors ​

ErrorStatusCause
NotFoundError404Webhook ID doesn't exist or belongs to another tenant
BadRequestError400Invalid event type, retry constraint exceeded

Delete Webhook ​

Permanently remove a webhook. This action is irreversible.

ts
const result = await outbound.webhooks.delete('webhook-uuid');
// { message: 'Webhook deleted', id: 'webhook-uuid' }

Possible Errors ​

ErrorStatusCause
NotFoundError404Webhook doesn't exist or belongs to another tenant

Testing your endpoint

There's no SDK/API method to send a test event — testing is a dashboard-only action (Webhooks page → "Send test event"). It dispatches a synthetic ping event (event: 'ping', status: 'ping') so you can confirm your endpoint receives and verifies deliveries before going live.


Verify Webhook Signature ​

When your endpoint receives a webhook, always verify the signature to confirm it came from the Outbound platform. The platform signs every payload using HMAC-SHA256 with your webhook secret.

How Signatures Work ​

  1. The platform signs the raw request body with HMAC-SHA256(body, your_secret)
  2. Sends the hex-encoded signature in the X-Webhook-Signature header
  3. Also sends X-Webhook-Id, X-Webhook-Timestamp, and (v2) X-Webhook-Delivery-Id

Sign the raw body

Verify against the exact bytes received, not a re-serialized object. Use a raw-body parser (e.g. express.raw) so the bytes match what was signed.

Verification with the SDK ​

ts
import { Outbound } from '@masters-union/outbound-sdk';

app.post('/webhooks/outbound', (req, res) => {
  const signature = req.headers['x-webhook-signature'];

  const isValid = Outbound.verifyWebhookSignature(
    req.rawBody,                 // the exact bytes received
    signature,
    process.env.WEBHOOK_SECRET  // the secret from webhooks.create()
  );

  if (!isValid) {
    return res.status(401).send('Invalid signature');
  }

  // Signature verified — process the event
  const event = req.body;
  console.log(`Event: ${event.type} for ${event.email}`);

  res.status(200).send('OK');
});

Manual Verification (without the SDK) ​

ts
import crypto from 'crypto';

function verifySignature(payload: string, signature: string, secret: string): boolean {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(signature, 'hex'),
    Buffer.from(expected, 'hex')
  );
}

WARNING

Always verify webhook signatures in production to prevent spoofed events. Use crypto.timingSafeEqual (not ===) to prevent timing attacks.


Webhook Payload Format ​

A delivery is a batch — always iterate events. The v2 envelope (IncomingWebhookPayloadV2):

ts
{
  webhookId: '1f3a…',
  webhookDeliveryId: 'd8c1…',          // also in X-Webhook-Delivery-Id; stable across retries
  version: 2,
  timestamp: '2026-06-21T10:00:00.000Z',
  events: [ /* IncomingWebhookEventV2[] */ ]
}

Each event:

ts
{
  eventId: '9b2e…',             // stable per-event idempotency key
  messageId: '019ee6ec-…',      // shared by the To, CC and BCC recipients of one email
  campaignId: 'AUTM-000449',    // or null
  event: 'bounce',              // verb
  status: 'bounced',            // mapped status
  email: 'user@example.com',    // the recipient this event belongs to (can be a CC or BCC)
  subject: 'Welcome',
  metadata: { lead_id: '98765', recipientEmail: 'user@example.com' }, // recipientEmail always equals email
  details: { /* event-specific, below */ },
  timestamp: '2026-06-21T09:59:58.000Z',  // when it occurred
  receivedAt: '2026-06-21T10:00:00.100Z'  // when we received it
}

details by event ​

eventstatusdetails
sendsent—
deliverydelivered—
bouncebouncedbounceType, bounceSubType, smtpStatus, diagnosticCode, failedReason, suppressed
complaintcomplainedcomplaintType, suppressed
openopeneduserAgent, ip, likelyAutomated, automatedReason
clickclickedlink, userAgent, ip, likelyAutomated, automatedReason
rejectrejectedfailedReason
rendering_failurerendering_failedfailedReason
failedfailedfailedReason
unsubscribeunsubscribed—
resubscriberesubscribed—
replyrepliedreplyId, threadId, replyType, direction, from, fromName, replySubject, newText, snippet, attachmentCount, senderAuth, participant, outOfOffice, optOutDetected, optOutAction, simulated, receivedAt
auto_replyauto_repliedSame as reply
inboundreceivedmailboxId, mailboxAddress, recipient, tag, from, subject, text, attachments and more. See Inbound Events

likelyAutomated: true (open/click) means software most likely made the event, not a person. automatedReason says why: mail_privacy_proxy (a privacy service such as Apple Mail Privacy Protection loaded the images by itself), link_scanner (a desktop browser clicked within a minute of sending, which is how security scanners behave) or bot_detected (our delivery network flagged it). Automatic events still count as opens and clicks; filter on likelyAutomated if you only want human engagement.

suppressed: true (bounce/complaint) means the address was auto-added to your suppression list. unsubscribe/resubscribe are platform events from the unsubscribe page (not provider events).

failedReason is a stable Outbound sentence rather than raw provider text: for a known bounceSubType it is our own wording (OnAccountSuppressionList → "This address is on your suppression list. Dropped."), otherwise it falls back to the receiving mail server's diagnostic. diagnosticCode is that remote diagnostic verbatim, minus infrastructure-provider branding and provider documentation links; third-party text is untouched, so a Gmail bounce keeps its support.google.com explanation. Branch on bounceType / bounceSubType / smtpStatus in code and treat both reason strings as display text.

Types are exported: IncomingWebhookPayloadV2, IncomingWebhookEventV2, WebhookEventDetails, WebhookEventStatus, and AnyIncomingWebhookPayload (a union of v1 and v2 — discriminate on version).

Legacy v1 payload

Webhooks created before v2 deliver the raw provider event. Discriminate by the absence of version:

ts
{ webhookId, timestamp, events: [{ eventType, messageId, data /* raw SES event */, timestamp }] }

Conversation Events ​

reply and auto_reply fire for emails sent with captureReplies: true. Subscribe to them like any other event. reply covers every message a person writes in the conversation, including your own team's replies, so one subscription gives you the whole thread. details.replyType and details.participant say who wrote it.

  • messageId is the email that was replied to. That can be the original email or a reply your team sent from Outbound, so group events by details.threadId.
  • email is the recipient of the email that was replied to, normally the person you emailed. The actual sender is details.from, which differs when the email was forwarded.
  • subject is the subject of the email that was replied to. The reply's own subject is details.replySubject.
  • For a reply your team sent from Outbound (replyType: staff_reply, direction: outbound), messageId is that reply's own email and email is the person it was sent to.
ts
{
  eventId: '0199f1c3-1d2e-7a4b-9c8d-6e5f4a3b2c1d',
  messageId: '0199f1a0-77b2-7e10-8c4d-5b1f2e9a3c71',
  campaignId: 'Q3-LEADS',
  event: 'reply',
  status: 'replied',
  email: 'riya@example.com',
  subject: 'Your application',
  metadata: { lead_id: '98765', recipientEmail: 'riya@example.com' },
  details: {
    replyId: '0199f1c3-1d2e-7a4b-9c8d-6e5f4a3b2c1d',
    threadId: '0199f1c2-5a4e-7c1d-9a3b-2f6e8d4c1a10',
    replyType: 'reply',
    direction: 'inbound',
    from: 'riya@example.com',
    fromName: 'Riya Sharma',
    replySubject: 'Re: Your application',
    newText: 'Yes! What are the fees?',
    snippet: 'Yes! What are the fees?',
    attachmentCount: 0,
    senderAuth: 'verified',
    participant: 'recipient',
    outOfOffice: false,
    optOutDetected: false,
    optOutAction: null,
    simulated: false,
    receivedAt: '2026-10-18T10:02:11.000Z'
  },
  timestamp: '2026-10-18T10:02:11.000Z',
  receivedAt: '2026-10-18T10:02:12.400Z'
}
DetailDescription
replyIdID of the message in the conversation. conversations.getThread(threadId) returns it with its full text
threadIdThe conversation the message belongs to
replyTypeThe message kind: reply, auto_reply, bounce, read_receipt or staff_reply. The auto_reply event also covers bounce notices and read receipts
directioninbound, or outbound for a reply your team sent from Outbound
from / fromNameWho sent the message
replySubjectSubject of the message itself
newTextWhat the message added, with the quoted history removed
snippetA short preview
attachmentCountNumber of attachments
senderAuthverified, unverified, failed or internal. See Who Sent a Message
participantrecipient, staff or external
outOfOfficeThe message is an out-of-office reply
optOutDetected / optOutActionThe message asked to stop, and what was done about it: flagged, suppressed or already_suppressed. See Opt-Out Replies
simulatedCreated with the Sandbox
receivedAtWhen the message was received, or sent for a reply your team sent from Outbound

newText, snippet, from, fromName and replySubject are written by whoever sent the message. Escape them before rendering them anywhere.

When a reply asking to stop is suppressed automatically, an unsubscribe event for the same email fires as well, with details.unsubscribeSource: 'reply', details.unsubscribeReason: 'reply' and the phrase that matched in details.unsubscribeComment.


Inbound Events ​

inbound fires when an email is delivered to one of your mailboxes. It fires once for each mailbox that receives the message. Mail that is blocked, because the mailbox is turned off, its allowed senders reject the sender, the mail is spam or a virus, or the hourly limit is reached, does not fire it. Neither does mail to a deleted mailbox. See What Is Not Delivered.

Subscribe to it like any other event:

ts
await outbound.webhooks.create({
  url: 'https://myapp.com/webhooks/outbound-inbound',
  events: ['inbound'],
});
  • status is received. It describes a message that arrived at your mailbox. It is not a delivery status of an email you sent.
  • messageId is the ID of the received message, not of an email you sent. Pass it to mailboxes.getMessage() to read the full message.
  • email is the mailbox address, localPart@replyDomain. The sender is in details.from. The exact address the message was sent to, including any +tag, is in details.recipient.
  • subject is the subject of the message.
  • metadata is the metadata of the mailbox, as you set it when you created or updated the mailbox.
  • campaignId is always null. Inbound mail is not part of a campaign.
  • eventId is the same as messageId and stays the same across retries. Use it to skip events you have already handled.

A single v2 delivery with one inbound event:

json
{
  "webhookId": "8d8b214b-0747-4ff8-949c-2625a9b7d220",
  "webhookDeliveryId": "d8c1f0a2-3b4e-4c5d-9e6f-7a8b9c0d1e2f",
  "version": 2,
  "timestamp": "2026-11-23T09:14:02.000Z",
  "events": [
    {
      "eventId": "0199f2b7-1c3a-7e9d-b5f4-8a2c6d0e1f23",
      "messageId": "0199f2b7-1c3a-7e9d-b5f4-8a2c6d0e1f23",
      "campaignId": null,
      "event": "inbound",
      "status": "received",
      "email": "claude-otp@inbound.example.com",
      "subject": "Your login code is 482913",
      "metadata": { "purpose": "otp" },
      "details": {
        "mailboxId": "0199f2a4-6b1e-7c3d-8e2f-4a5b6c7d8e9f",
        "mailboxAddress": "claude-otp@inbound.example.com",
        "recipient": "claude-otp+gmail@inbound.example.com",
        "tag": "gmail",
        "from": "noreply@accounts.example.org",
        "fromName": "Example Accounts",
        "replyTo": [],
        "to": ["claude-otp+gmail@inbound.example.com"],
        "cc": [],
        "subject": "Your login code is 482913",
        "text": "Your login code is 482913.\n\nUse this code to finish signing in. It expires in 10 minutes.",
        "textTruncated": false,
        "snippet": "Use this code to finish signing in. It expires in 10 minutes.",
        "hasHtml": true,
        "attachmentCount": 0,
        "attachments": [],
        "senderAuth": "verified",
        "automated": true,
        "automatedReason": null,
        "sizeBytes": 18432,
        "rfcMessageId": "<8d1c2f@accounts.example.org>",
        "simulated": false,
        "receivedAt": "2026-11-23T09:14:02.000Z"
      },
      "timestamp": "2026-11-23T09:14:02.000Z",
      "receivedAt": "2026-11-23T09:14:02.300Z"
    }
  ]
}

The fields of details for an inbound event:

FieldTypeDescription
mailboxIdstringThe mailbox that received the message. Use it with the Mailboxes methods
mailboxAddressstringThe mailbox address, localPart@replyDomain
recipientstringThe exact address the message was sent to, including any +tag
tagstring | nullThe plus tag without the +, or null
fromstring | nullThe sender's address from the From header. Sender-written
fromNamestring | nullThe sender's display name. Sender-written
replyTostring[]Reply-To addresses
tostring[]To addresses
ccstring[]CC addresses
subjectstring | nullThe subject of the message. Sender-written, so escape it before you render it
textstring | nullThe plain text body, capped in length. Sender-written, so escape it before you render it
textTruncatedbooleantrue when text was cut short. The rest of the body is not stored
snippetstring | nullA short preview of the plain text
hasHtmlbooleantrue when the message has an HTML body. Fetch it with mailboxes.getMessageHtml()
attachmentCountnumberNumber of attachments
attachmentsobject[]Attachment metadata: id, filename, contentType, size and inline. Download a file with mailboxes.getAttachment()
senderAuthstring | nullverified, unverified, failed or internal. Treat failed with suspicion
automatedbooleantrue when the message looks machine-generated, such as an auto-reply or a notification
automatedReasonstring | nullWhy automated is true, as a code. Do not branch on the wording
sizeBytesnumber | nullSize of the raw message in bytes
rfcMessageIdstring | nullThe Message-ID header
simulatedbooleantrue when the email was created with sandbox.simulateInbound() rather than sent by a real sender
receivedAtstringWhen the message was received

Retry Behavior ​

If your endpoint returns a non-2xx status code or times out, the platform retries delivery. The wait between attempts depends on the webhook's retryStrategy:

Exponential (default) — the wait doubles after each failed attempt:

  1. First attempt — immediate
  2. Retry 1 — after retryInterval seconds (default: 5 minutes)
  3. Retry 2 — after retryInterval × 2 seconds (default: 10 minutes)
  4. Retry 3 — after retryInterval × 4 seconds (default: 20 minutes), and so on up to maxRetries

Linear — every retry waits a flat retryInterval:

  1. First attempt — immediate
  2. Retry 1 — after retryInterval seconds
  3. Retry 2 — after another retryInterval seconds
  4. Retry 3 — final attempt (based on maxRetries)

A delivery that fails all of its retries is marked exhausted. When maxRetries consecutive deliveries (minimum 1) each exhaust their retries, the webhook status is set to defective and no further events are sent until you re-enable it. Any successful delivery in between resets the streak.

Best Practices

  • Return 200 quickly — process events asynchronously after responding
  • Handle duplicates — the same event may be delivered more than once during retries
  • Use the eventId as your idempotency key. It is stable per event across retries and redeliveries. messageId is the per-recipient correlation id, so it repeats across every event for that email (delivery, open, click) and deduping on it would collapse them into one. To dedupe a whole batch instead, use webhookDeliveryId / X-Webhook-Delivery-Id
  • Monitor webhook status — check outbound.webhooks.list() periodically for defective webhooks

Complete Example: Webhook Lifecycle ​

ts
import { Outbound } from '@masters-union/outbound-sdk';
import express from 'express';

const outbound = new Outbound({ apiKey: 'mu_outbound_...' });
const app = express();
app.use(express.json());

// 1. Create a webhook
const { webhook, secret } = await outbound.webhooks.create({
  url: 'https://myapp.com/webhooks/outbound',
  events: ['delivery', 'bounce', 'complaint', 'open', 'click'],
});

// Save the secret to your config/env
console.log('Webhook secret:', secret);

// 2. Handle incoming events
app.post('/webhooks/outbound', (req, res) => {
  const signature = req.headers['x-outbound-signature'];

  if (!Outbound.verifyWebhookSignature(JSON.stringify(req.body), signature, secret)) {
    return res.status(401).send('Invalid signature');
  }

  const event = req.body;

  switch (event.type) {
    case 'delivery':
      console.log(`Delivered to ${event.email}`);
      break;
    case 'bounce':
      console.log(`Bounced: ${event.email} (${event.bounceType})`);
      break;
    case 'complaint':
      console.log(`Complaint from ${event.email}`);
      break;
    case 'open':
      console.log(`Opened by ${event.email}`);
      break;
    case 'click':
      console.log(`Clicked by ${event.email}: ${event.link}`);
      break;
  }

  res.status(200).send('OK');
});

// 3. List your webhooks
const { webhooks } = await outbound.webhooks.list();
console.log(`You have ${webhooks.length} webhook(s)`);

// 4. Update events
await outbound.webhooks.update(webhook.id, {
  events: ['delivery', 'bounce', 'complaint'],
});

// 5. Delete when no longer needed
await outbound.webhooks.delete(webhook.id);

Released under the MIT License.