← All use cases

Webhook Development & Testing

Build and debug email-triggered webhooks

MailBrew webhooks notify your application when an email arrives. Build and test email-driven workflows such as creating support tickets, processing order confirmations, and sending alerts.

What you can do with MailBrew

  1. 01

    Notified on arrival

    When an email arrives, MailBrew POSTs JSON to the URL you registered. No need to build your own polling to check for new mail.

  2. 02

    Payload and signature

    Receive the address plus the email ID, sender, subject, text body, and received time as JSON. The X-Mailbrew-Signature header lets you confirm the request came from MailBrew (Slack URLs receive a Slack-formatted message instead).

  3. 03

    Retries and delivery log

    If your endpoint returns 5xx or cannot be reached, MailBrew retries at increasing intervals (up to 5 attempts in total). Results appear on the Webhooks page, and owners can resend manually. A webhook that keeps failing is turned off automatically and owners are notified.

  4. 04

    Local development

    Expose your local server with ngrok, Cloudflare Tunnel, or a similar tool to receive and debug webhooks on your machine.

Sample code

JavaScript (Express)

JavaScript (Express)
// Express.js: Receive MailBrew webhooks (verify the signature first)
const crypto = require('crypto');
const express = require('express');
const app = express();

// The signature is HMAC-SHA256 of "timestamp.raw body", keyed with the webhook secret
app.post('/webhook/mailbrew', express.raw({ type: 'application/json' }), (req, res) => {
  // Reject stale deliveries: timestamps older than 5 minutes (300 s)
  const timestamp = req.get('X-Mailbrew-Timestamp') || '';
  if (!/^\d+$/.test(timestamp)) return res.status(401).end();
  if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > 300) return res.status(401).end();

  const expected = 'sha256=' + crypto.createHmac('sha256', process.env.MAILBREW_WEBHOOK_SECRET)
    .update(`${timestamp}.${req.body}`)
    .digest('hex');
  const signature = req.get('X-Mailbrew-Signature') ?? '';
  if (signature.length !== expected.length
      || !crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return res.status(401).end();
  }

  const { address, email } = JSON.parse(req.body);
  const subject = email.subject ?? '';
  console.log(`New email at ${address}: ${subject}`);

  if (subject.includes('Order Confirmation')) {
    processOrder(email);
  } else if (subject.includes('Support')) {
    createTicket(email);
  }

  res.status(200).json({ received: true });
});

app.listen(3000);

Ready to try this use case?

Get started with the free plan today. No credit card required.
Free plan: up to 100 emails/month and 5 addresses

Create free account →