API Documentation

MailBrew REST API Reference

Playground →

Getting Started

MailBrew can be used in two ways.

SMTP
SMTP Mode (Email Send Testing)

Point your app's SMTP to MailBrew (smtp.mailbrew.dev). View sent emails in your dashboard's shared inbox in real time.

SMTP Config →
Cloud API
Cloud API Mode (E2E & CI Testing)

Create test email addresses via API, receive real emails, and automate OTP extraction, link verification, and email assertions. CI/CD ready.

Cloud API →

SMTP Configuration

Set the following environment variables in your application.

Use SMTP credentials generated in the Dashboard "SMTP Settings" page. All emails sent with these credentials are automatically routed to your company's shared inbox, regardless of the recipient address. No need to worry about recipient addresses during testing.

Laravel (.env)

Connections are encrypted. Use port 587 (STARTTLS, recommended) or 465 (SSL/TLS). Port 587 refuses authentication until the connection is encrypted.

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailbrew.dev
MAIL_PORT=587
MAIL_USERNAME=mb_smtp_xxxxx
MAIL_PASSWORD=your_smtp_password
MAIL_ENCRYPTION=tls

Laravel 11+ encrypts automatically with MAIL_PORT=587 (MAIL_ENCRYPTION=tls is for Laravel 10 and earlier). For port 465 use MAIL_PORT=465 and MAIL_SCHEME=smtps (MAIL_ENCRYPTION=ssl on Laravel 10 and earlier).

For Node.js (Nodemailer):

const transporter = nodemailer.createTransport({
  host: 'smtp.mailbrew.dev',
  port: 587,
  secure: false,      // STARTTLS on 587 (for 465: port: 465, secure: true)
  requireTLS: true,
  auth: {
    user: 'mb_smtp_xxxxx',
    pass: 'your_smtp_password',
  },
});

Web UI

Emails sent to MailBrew can be viewed in real-time via the Web UI. Supports HTML preview, attachment downloads, and search by subject or sender.

https://mailbrew.dev

Cloud API

The following are MailBrew cloud service API endpoints. Authentication with an API key is required.

SDKs

Use our official SDKs for easy API integration.

npm install @mailbrew/sdk
const { MailBrew } = require('@mailbrew/sdk');
const client = new MailBrew('mb_your_key_here');

Methods

Address Management
createAddress(options?)

Create a temporary email address

const addr = await client.createAddress({ ttl: 3600 });
console.log(addr.address); // "[email protected]"
listAddresses()

List all addresses

const addresses = await client.listAddresses();
deleteAddress(address)

Delete an address

await client.deleteAddress('[email protected]');
Email Operations
waitForEmail(address, options?)

Wait for email via long-polling

const email = await client.waitForEmail(addr.address, { timeout: 30000 });
listEmails(address)

List emails for an address

const emails = await client.listEmails(addr.address);
getEmail(address, emailId)

Get email details

const detail = await client.getEmail(addr.address, email.id);
Data Extraction
extractOtp(address, emailId, options?)

Extract OTP/verification code from email

const code = await client.extractOtp(addr.address, email.id);
// Custom pattern: { pattern: '\\d{4}' }
extractLinks(address, emailId, options?)

Extract links from email

const links = await client.extractLinks(addr.address, email.id);
// Filter: { pattern: 'verify' }
extractLinkItems(address, emailId, options?)

Extract links with anchor text and kind (verify / password_reset / unsubscribe / other) (Node.js SDK 2.2.0 and later; not yet published)

const [verify] = await client.extractLinkItems(addr.address, email.id, { kind: 'verify' });
console.log(verify.url);
assertEmail(address, emailId, assertions)

Assert email properties (subject, from, body, etc.)

const result = await client.assertEmail(addr.address, email.id, {
  subject_contains: 'Welcome',
  body_contains: 'verify',
});
console.log(result.passed); // true
Convenience
captureOtp(options?)

Create address + wait + extract OTP in one call

const { address, waitAndExtract } = await client.captureOtp({ ttl: 120 });
// ... trigger email ...
const { code, email } = await waitAndExtract();
forwardEmail(address, emailId, to)

Forward email to an active, verified member of your company

await client.forwardEmail(addr.address, email.id, '[email protected]');
deleteAllEmails(address)

Delete every email of an address (emails:delete; clean up after a test) (Node.js SDK 2.2.0 and later; not yet published)

const deleted = await client.deleteAllEmails(addr.address);
Webhooks
createWebhook(url, options?)

Create a global webhook

const wh = await client.createWebhook('https://example.com/hook', {
  events: ['email.received'],
});
listWebhooks()

List webhooks

const webhooks = await client.listWebhooks();
deleteWebhook(id)

Delete a webhook

await client.deleteWebhook(wh.id);

Authentication

All API requests require an API key. Include it in the X-API-Key header.

X-API-Key: mb_your_key_here

Scopes

If an API key has scopes assigned, requests without the required scope will return a 403 error. Keys without scopes have full access.

addresses:read— List and view addresses
addresses:write— Create addresses
addresses:delete— Delete addresses
emails:read— List, wait for, get raw source and attachments, extract OTP and links, assert, diff and check deliverability
emails:forward— Forward emails to active, verified members of your company
emails:delete— Delete emails (one, all for an address, or all for an external recipient)
webhooks:read— List webhooks
webhooks:write— Create and update webhooks
webhooks:delete— Delete webhooks

Address Format

Generated addresses use your company subdomain. If a custom domain is configured, it will be used instead.

{random}@{company-slug}.mailbrew.dev

Base URL

https://mailbrew.dev/api/mailbrew

API errors

Common causes for each status.

401
The API key is wrong or has been deleted. Check that you send it in the X-API-Key header.
403
The key does not have the scope for this operation, the request comes from an IP address outside your allowlist, the address or monthly limit is reached, or the account is disabled.
404
The address does not exist, belongs to another company or to another API key, the email was deleted after the retention period, the email ID is wrong, or no OTP was found. You can wait for an address that does not exist yet with the wait endpoint if it uses your own domain.
410
You called wait on an address created through the API whose TTL has expired. You can still read its emails during the company retention period (7 days by default).
422
A value is missing or has the wrong shape, local_part is already in use, or the assertion has no conditions. Send JSON with Content-Type: application/json.
429
You exceeded the calls per minute or the number of concurrent waits. Wait for the number of seconds in Retry-After.

The language of error messages follows the Accept-Language header (send Accept-Language: ja for Japanese). Without it, messages are in English. Identifiers such as scope names (emails:read) and codes are written the same way in every language. Messages about invalid regex patterns are in English only.

Rate limit headers

On plans with a rate limit, the response headers tell you how many calls you have left. The limit is counted per company, not per API key.

Retry-After
How many seconds to wait (returned on 429).
X-RateLimit-Limit
The limit per minute.
X-RateLimit-Remaining
How many calls are left in this minute.

Verifying webhook signatures

Every delivery carries X-Mailbrew-Timestamp (the send time in UNIX seconds) and X-Mailbrew-Signature: sha256=…. Compare the received signature with the HMAC-SHA256 of "{timestamp}.{body}" computed with your signing secret, and compare them in constant time. Use the raw body bytes, and reject anything whose timestamp differs from the current time by more than 300 seconds (5 minutes).

X-Mailbrew-Timestamp
The send time in UNIX seconds.
X-Mailbrew-Signature
sha256=HMAC-SHA256(secret, "timestamp.body").
const timestamp = req.get('X-Mailbrew-Timestamp') || '';
if (!/^\d+$/.test(timestamp)) return res.sendStatus(401);
if (Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > 300) return res.sendStatus(401);

const expected = 'sha256=' + crypto.createHmac('sha256', process.env.MAILBREW_WEBHOOK_SECRET)
  .update(timestamp + '.').update(req.body).digest('hex');

const received = Buffer.from(req.get('X-Mailbrew-Signature') || '');
const expectedBuffer = Buffer.from(expected);
if (received.length !== expectedBuffer.length || !crypto.timingSafeEqual(received, expectedBuffer)) {
  return res.sendStatus(401);
}

Deliveries to a registered webhook are signed with that webhook's secret (returned when you create it and shown on the Webhooks page of the dashboard, owners only). Deliveries to a per-address webhook_url are signed with your company signing secret.

Endpoints

POST
/api/mailbrew/addresses
addresses:write

Create Address — Generate an email address. Set ttl=0 to create a permanent (non-expiring) address.

Parameters

ttlinteger
optional
Time to live in seconds. Default 3600. Maximum 31536000 (1 year). Set 0 for permanent
webhook_urlstring
optional
Notification URL on email receipt (per-address)
local_partstring
optional
Custom local part

Response

{
  "data": {
    "id": 1,
    "address": "[email protected]",
    "webhook_url": null,
    "expires_at": "2026-03-29T13:00:00+00:00",
    "is_permanent": false,
    "created_at": "2026-03-29T12:00:00+00:00"
  }
}
GET
/api/mailbrew/addresses
addresses:read

List Addresses — Returns the addresses created with this API key and the addresses auto-created on receipt for the same company. Auto-created addresses can be read with any API key from the same company.

Response

{
  "data": [
    {
      "id": 1,
      "address": "[email protected]",
      "webhook_url": null,
      "expires_at": "2026-03-29T13:00:00+00:00",
      "is_permanent": false,
      "created_at": "2026-03-29T12:00:00+00:00"
    }
  ]
}
GET
/api/mailbrew/addresses/{address}
addresses:read

Get Address — Get details of an address.

Response

{
  "data": {
    "id": 1,
    "address": "[email protected]",
    "webhook_url": null,
    "expires_at": "2026-03-29T13:00:00+00:00",
    "is_permanent": false,
    "created_at": "2026-03-29T12:00:00+00:00"
  }
}
GET
/api/mailbrew/addresses/{address}/emails
emails:read

List Emails — List emails received at the specified address. Emails are deleted after the retention period (7 days on every plan; organizations can shorten it in Security settings).

Parameters

limitinteger
optional
Number of emails to return, newest first (1-100). Omit for all
beforeinteger
optional
Return emails older than this email ID. Pass meta.next_before from the previous response

Response

{
  "data": [
    {
      "id": 1,
      "from_address": "[email protected]",
      "subject": "Your verification code",
      "text_body": "Your code is: 847291",
      "received_at": "2026-03-29T12:05:00+00:00",
      "attachments": [{ "id": 7, "filename": "invoice.pdf", "content_type": "application/pdf", "size": 20480 }]
    }
  ],
  "meta": { "has_more": true, "next_before": 1 }
}
DELETE
/api/mailbrew/addresses/{address}/emails
emails:delete

Delete All Emails — Delete all emails (and attachments) received at the address. Useful for cleaning up after a test. Emails also delivered to another company are only removed from your inbox.

Response

{ "data": { "deleted": 3 } }
GET
/api/mailbrew/addresses/{address}/emails/{id}
emails:read

Get Email — Get details of a specific email.

Response

{
  "data": {
    "id": 1,
    "from_address": "[email protected]",
    "subject": "Your verification code",
    "text_body": "Your code is: 847291",
    "html_body": "<p>Your code is: <b>847291</b></p>",
    "received_at": "2026-03-29T12:05:00+00:00"
  }
}
DELETE
/api/mailbrew/addresses/{address}/emails/{id}
emails:delete

Delete Email — Delete an email and its attachments. This cannot be undone.

Response

204 No Content
GET
/api/mailbrew/addresses/{address}/emails/{id}/raw
emails:read

Raw Source — Return the email exactly as received (headers and MIME structure) as message/rfc822.

Response

From: [email protected]
To: [email protected]
Subject: Your verification code
...
GET
/api/mailbrew/addresses/{address}/emails/{id}/attachments/{attachmentId}
emails:read

Download Attachment — Download an attachment. The attachment ID is in the email list's attachments (not included in the single-email and wait responses).

Response

(binary)
GET
/api/mailbrew/addresses/{address}/emails/{id}/otp
emails:read

Extract OTP — Auto-extract OTP/verification codes from email body. Without pattern, the candidates considered (value, confidence, position) are returned in candidates.

Parameters

patternstring
optional
Custom regex pattern. Write a capture group ( ) to get the captured part instead of the whole match (e.g. Code: (\d{6}))

Response

{
  "data": {
    "code": "847291",
    "email_id": 1,
    "source": "text_body",
    "candidates": [
      { "value": "847291", "confidence": "high", "position": 13 }
    ]
  }
}
GET
/api/mailbrew/addresses/{address}/emails/{id}/links
emails:read

Extract Links — Auto-extract links (URLs) from email body. items include anchor text and kind (verify, password reset, unsubscribe), so kind=verify returns just the verification link.

Parameters

patternstring
optional
Regex pattern the URL must match
kindstring
optional
Filter by kind (verify / password_reset / unsubscribe / other)
textstring
optional
Only links whose anchor text contains this (case-insensitive)

Response

{
  "data": {
    "links": [
      "https://example.com/verify?token=abc123",
      "https://example.com/unsubscribe"
    ],
    "items": [
      { "url": "https://example.com/verify?token=abc123", "text": "Verify your email", "kind": "verify" },
      { "url": "https://example.com/unsubscribe", "text": "Unsubscribe", "kind": "unsubscribe" }
    ],
    "email_id": 1,
    "source": "text_body"
  }
}
POST
/api/mailbrew/addresses/{address}/emails/{id}/assert
emails:read

Assert Email — Validate email content. Check subject, sender, recipient, body, headers and attachments simultaneously.

Parameters

subjectstring
optional
Exact subject match (case-sensitive)
subject_containsstring
optional
Subject contains (case-sensitive)
subject_matchesstring
optional
Subject matches the regex (no delimiters, max 200 chars, no "/")
fromstring
optional
Exact from address match
tostring
optional
One of the recipients (case-insensitive)
body_containsstring
optional
Body contains (case-insensitive; text body, or HTML body when there is no text body)
body_not_containsstring
optional
Body does not contain (same body as body_contains)
body_matchesstring
optional
Body matches the regex (same body as body_contains)
html_containsstring
optional
HTML body contains (case-insensitive)
headerobject
optional
Header exists ({ "name": "List-Unsubscribe" }); with value, its value contains the text
has_attachmentboolean
optional
Has (true) or has no (false) attachments
attachment_filenamestring
optional
An attachment has this file name (case-insensitive)

Response

{
  "data": {
    "passed": true,
    "email_id": 1,
    "results": [
      { "field": "subject", "passed": true, "expected": "Welcome", "actual": "Welcome" },
      { "field": "body_contains", "passed": true, "expected": "verify" }
    ]
  }
}
POST
/api/mailbrew/addresses/{address}/emails/{id}/forward
emails:forward

Forward Email — Forward a received email only to an active, verified member of your company.

Parameters

tostring
required
Email address of an active, verified member of your company

Response

{
  "data": {
    "forwarded": true,
    "to": "[email protected]"
  },
  "success": true
}
DELETE
/api/mailbrew/addresses/{address}
addresses:delete

Delete Address — Delete an address.

Response

204 No Content
GET
/api/mailbrew/addresses/{address}/emails/wait
emails:read

Wait for Emails — Wait for emails using long-polling.

Parameters

timeoutinteger
optional
Wait seconds (1-60, default 30)
sincestring
optional
Emails received at or after this ISO8601 timestamp (rounded to the second)
countinteger
optional
Number of emails to wait for (1-100, default 1). With conditions, the number of matching emails
(条件)—
optional
Filter with the same conditions as assertions (except to). Only matching emails are counted and returned. e.g. subject_contains=Verify, has_attachment=true, header[name]=List-Unsubscribe
extractstring
optional
otp, links (comma-separated). Adds extracted (otp: { code, candidates } or null, links) to each email, so you can skip a second request

Response

{ "data": [] }
POST
/api/mailbrew/addresses/{address}/sequence
emails:read

Verify Email Sequence — Verify that matching emails arrive in order.

Parameters

stepsarray
required
Array of assertion conditions for each email
timeoutinteger
optional
Wait seconds (1-60, default 30)

Response

{ "data": { "passed": true, "steps": [] } }
POST
/api/mailbrew/addresses/{address}/emails/{id}/diff
emails:read

Compare Emails — Compare two emails.

Parameters

againstinteger
required
Email ID to compare against

Response

{ "data": { "email_id": 1, "against_id": 2, "fields": {} } }
GET
/api/mailbrew/addresses/{address}/emails/{id}/deliverability
emails:read

Analyze Deliverability — Analyze deliverability including SPF, DKIM, and DMARC. requirements lists pass/fail and how to fix for each Gmail sender-guideline requirement that one message can show (not part of the score).

Response

{
  "data": {
    "score": 100,
    "checks": [],
    "recommendations": [],
    "requirements": [
      { "id": "one_click_unsubscribe", "applies_to": "bulk_marketing", "status": "fail", "detail": "No List-Unsubscribe header", "fix": "Add List-Unsubscribe: <https://...> and List-Unsubscribe-Post: List-Unsubscribe=One-Click (RFC 8058)" }
    ]
  }
}
GET
/api/mailbrew/emails
emails:read

List Captured Emails — List emails sent over SMTP AUTH to external recipients (e.g. gmail.com), looked up by envelope recipient (RCPT TO), including BCC. A MailBrew address cannot be used as to (use the address endpoints). Get one, extract OTP or links, or fetch the raw source or attachments with /api/mailbrew/emails/{id}, /otp, /links, /raw and /attachments/{attachmentId}; delete with DELETE /api/mailbrew/emails/{id}.

Parameters

tostring
required
Envelope recipient email address
sincestring
optional
Emails received at or after this ISO8601 timestamp (rounded to the second)
limitinteger
optional
Number of emails to return, newest first (1-100). Omit for all
beforeinteger
optional
Return emails older than this email ID. Pass meta.next_before from the previous response

Response

{
  "data": [
    {
      "id": 1,
      "from_address": "[email protected]",
      "subject": "Your verification code",
      "text_body": "Your code is: 847291",
      "received_at": "2026-03-29T12:05:00+00:00"
    }
  ],
  "meta": { "has_more": false, "next_before": null }
}
DELETE
/api/mailbrew/emails
emails:delete

Delete Captured Emails — Delete all captured emails for the envelope recipient. to is required.

Parameters

tostring
required
Envelope recipient email address

Response

{ "data": { "deleted": 2 } }
GET
/api/mailbrew/emails/wait
emails:read

Wait for Captured Emails — Wait for captured emails using long-polling. Same parameters as waiting on an address.

Parameters

tostring
required
Envelope recipient email address
timeoutinteger
optional
Wait seconds (1-60, default 30)
sincestring
optional
Emails received at or after this ISO8601 timestamp (rounded to the second)
countinteger
optional
Number of emails to wait for (1-100, default 1). With conditions, the number of matching emails
(条件)—
optional
Filter with the same conditions as assertions (except to). Only matching emails are counted and returned. e.g. subject_contains=Verify, has_attachment=true, header[name]=List-Unsubscribe
extractstring
optional
otp, links (comma-separated). Adds extracted (otp: { code, candidates } or null, links) to each email, so you can skip a second request

Response

{ "data": [] }
GET
/api/mailbrew/webhooks
webhooks:read

List Webhooks — List global webhooks.

Response

{
  "data": [
    {
      "id": 1,
      "url": "https://example.com/hook",
      "events": ["email.received"],
      "is_active": true
    }
  ]
}
POST
/api/mailbrew/webhooks
webhooks:write

Create Webhook — Register a global webhook. Notifies for all addresses.

Parameters

urlstring
required
Webhook URL
eventsarray
optional
Event array. Empty for all events
includearray
optional
Extra fields to send (to_addresses / html_body / attachments / otp / links). Omit for the default fields
redact_historyboolean
optional
Hide OTP and links in the delivery history (default false: keep what was sent)
filterobject
optional
Only send matching emails: address_prefix (recipient starts with) and the same keys as assertions

Response

{
  "data": {
    "id": 1,
    "url": "https://example.com/hook",
    "secret": "abc123...",
    "events": ["email.received"],
    "is_active": true
  }
}
PUT
/api/mailbrew/webhooks/{id}
webhooks:write

Update Webhook — Update a webhook URL, events, or active state.

Parameters

urlstring
optional
Webhook URL
eventsarray
optional
Event array
is_activeboolean
optional
Active state
includearray
optional
Extra fields to send (to_addresses / html_body / attachments / otp / links). Omit for the default fields
redact_historyboolean
optional
Hide OTP and links in the delivery history (default false: keep what was sent)
filterobject
optional
Only send matching emails: address_prefix (recipient starts with) and the same keys as assertions

Response

{ "data": { "id": 1, "url": "https://example.com/hook", "events": ["email.received"], "is_active": true } }
DELETE
/api/mailbrew/webhooks/{id}
webhooks:delete

Delete Webhook — Delete a webhook.

Response

204 No Content

Code Examples

const { MailBrew } = require('@mailbrew/sdk');
const client = new MailBrew('mb_your_key_here');

// E2E test: create address, wait for email, extract OTP
const { address, waitAndExtract } = await client.captureOtp({ ttl: 120 });

// ... trigger email send to `address` ...

const { code, email } = await waitAndExtract();
console.log(code); // "847291"