Skip to content
Mailwright

Docs

API and webhooks

Create a key, send emails, manage campaigns, and verify webhook signatures.

  1. 1

    Create a key

    Settings › API & webhooks. Copy it once.

  2. 2

    Send the header

    Authorization: Bearer or X-API-Key.

  3. 3

    Check the key

    GET /backend/v1/me returns workspace and limits.

Authentication

Every endpoint requires an API key via one of these headers:

Authorization: Bearer mw_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# or
X-API-Key: mw_live_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Keys are scoped to a single workspace, limited by permissions, IP allowlist, rate limit, and daily/monthly caps.

GET /v1/me

Returns workspace info, key details, usage, and limits. No special permission required — any valid key works.

curl -H "Authorization: Bearer YOUR_KEY" https://mailwright.tech/backend/v1/me

Response shape:

FieldTypeDescription
workspace.iduuidWorkspace ID
workspace.codestringWorkspace code
workspace.namestringWorkspace display name
workspace.planstringPlan tier
key.namestringKey name
key.prefixstringKey prefix (for identification)
key.permissionsarrayGranted permissions list
key.rate_limit_per_minutenumberPer-key request rate limit
usage.key.sends_todaynumberSends by this key today
usage.key.sends_monthnumberSends by this key this month
usage.account_monthobjectMonthly usage snapshot for the account
usage.account_sends_todaynumberAccount sends today
limits.planobjectPlan-level send limits

GET /v1/senders

Permission: senders.read. Lists sender identities this key may use.

Response shape:

FieldTypeDescription
senders[].iduuidSender identity ID
senders[].from_emailemailVerified sending address
senders[].display_namestringDisplay name shown in From
senders[].healthybooleanWhether the connection is active and healthy
senders[].daily_remainingnumberDaily send quota remaining (cap - sent_today)
rotation.enabledbooleanWhether rotation is enabled for this key

POST /v1/emails

Permission: send.plain. Queues a plain-text email. Returns 202 immediately; sends asynchronously.

Idempotency-Key: Optional header. Repeat within 24 hours returns original response with header Idempotent-Replayed: true.

Request body:

FieldRequiredTypeDescription
toyesemailRecipient email address
subjectyesstringSubject line (1–300 chars)
bodyyesstringEmail body (1–50000 chars)
sender_idnouuidOverride default sender identity
from_emailnoemailOverride from address
skip_validationnoboolBypass recipient MX check (default false)

Response (202):

{
  "id": "log-id",
  "status": "queued",
  "to": "recipient@example.com",
  "sender": "you@example.com"
}

Errors:

  • 422 recipient_suppressed — Address unsubscribed, bounced, or complained earlier.
  • 422 recipient_domain_invalid — Recipient domain has no mail server. Pass skip_validation=true to override.

POST /v1/emails/personalized

Permission: send.personalized. Queues a personalized email using templates with merge tags.

Merge tags: Use {name}, {company}, {email} in subject_template and body_template.

AI personalization: Set ai_personalize: true to have the LLM rewrite subject/body based on brief and lead context.

Request body:

FieldRequiredTypeDescription
toyesemailRecipient email address
subject_templateyesstringSubject template (1–300 chars)
body_templateyesstringBody template (1–50000 chars)
namenostringRecipient name (max 200 chars)
companynostringRecipient company (max 200 chars)
variablesnoobjectCustom merge variables (key: value)
ai_personalizenoboolEnable AI rewriting (default false)
briefnostringContext for AI (max 4000 chars)
sender_idnouuidOverride default sender
from_emailnoemailOverride from address
skip_validationnoboolBypass recipient MX check (default false)

Response (202):

{
  "id": "log-id",
  "status": "queued",
  "to": "recipient@example.com",
  "sender": "you@example.com",
  "ai_used": true,
  "subject": "Final subject after rendering"
}

GET /v1/emails/{id}

Any of these permissions works: send.plain, send.personalized, campaigns.read, analytics.read.

Response shape:

FieldTypeDescription
iduuidEmail log ID
toemailRecipient address
subjectstringRendered subject
statusstringEmail status
sent_atISO timestampWhen sent by your mail server
opened_atISO timestampWhen tracking pixel loaded
clicked_atISO timestampWhen tracked link clicked
bounce_classstring|nullHard/soft bounce classification
events[]arrayChronological event timeline
notestringsent means your mail server accepted it; it is not proof of inbox placement.

404 not_found if the email is not in this workspace.

POST /v1/campaigns

Permission: campaigns.create. Creates a draft campaign. It does NOT send until launched.

Request body:

FieldRequiredTypeDescription
nameyesstringCampaign name (1–120 chars)
subjectnostringTemplate subject (1–300 chars)
bodynostringTemplate body (1–50000 chars)
briefnostringBrief/context (max 4000 chars)
max_followupsnointFollow-up sequence length (0–5, default 2)
leads[].emailyesemailLead email address
leads[].namenostringLead name
leads[].companynostringLead company
leads[].customnoobjectCustom fields object

Notes: Only the first 10000 leads are processed. Suppressed and duplicate emails are skipped.

Response (201):

{
  "id": "campaign-id",
  "name": "Campaign name",
  "status": "draft",
  "total_leads": 150,
  "sent": 0,
  "created_at": "2026-11-15T00:00:00+00:00",
  "launched_at": null,
  "message": "Draft created. Leads are being verified. Generate and review drafts in the app, or launch via API when ready.",
  "leads_received": 160,
  "leads_added": 150,
  "leads_skipped": 10
}

GET /v1/campaigns

Permission: campaigns.read. Lists campaigns in the workspace (excluding API-created kind).

Query parameters: limit (default 200, max 200), offset (default 0).

Response shape:

{
  "campaigns": [
    {
      "id": "campaign-id",
      "name": "Campaign name",
      "status": "draft",
      "total_leads": 150,
      "sent": 0,
      "created_at": "2026-11-15T00:00:00+00:00",
      "launched_at": null
    }
  ],
  "total": 45,
  "limit": 200,
  "offset": 0
}

GET /v1/campaigns/{id}

Permission: campaigns.read. Returns a single campaign object.

404 not_found if campaign is not in this workspace or is kind="api".

GET /v1/campaigns/{id}/analytics

Permission: analytics.read. Returns campaign metrics.

Response shape:

MetricTypeDescription
sentintTotal sends
opensintOpen count (approximate)
clicksintLink click count
repliesintReply count
bouncesintBounce count
complaintsintSpam complaint count
suspected_machine_clicksintClicks filtered as bot activity
open_ratepercentOpens / sends × 100
reply_ratepercentReplies / sends × 100

caveat field: "Opens are approximate because some mail apps load images automatically."

POST /v1/campaigns/{id}/launch

Permission: campaigns.send. Starts campaign delivery. Runs a preflight check before launching.

Response (202):

{
  "campaign_id": "campaign-id",
  "status": "sending",
  "scheduled_drafts": 42
}

Errors:

  • 409 already_sending — Campaign is currently sending.
  • 400 preflight_failed — Issues must be fixed before sending (returned in issues array).

Error codes

HTTPCodeMeaning
401invalid_api_keyMissing, revoked, expired, or invalid API key
403ip_not_allowedCaller IP not in key's allowlist
403workspace_unavailableWorkspace is archived or deleted
403account_suspendedAccount has been suspended
403permission_deniedKey lacks required permission (message specifies which)
429rate_limitedRate limit exceeded (Retry-After header set)
429ai_limitAI provider limit reached (personalized only)
429key_daily_limitKey daily send cap reached
429key_monthly_limitKey monthly send cap reached
429plan_daily_limitAccount plan daily limit reached
429sender_daily_capSelected sender hit its daily cap
429no_sender_availableNo healthy sender in rotation has capacity
409already_sendingCampaign is already sending
409sender_unavailableSender paused, disconnected, or not tested
409api_sending_pausedAPI sending paused for workspace after safety check
422recipient_suppressedAddress previously suppressed (unsubscribed/bounced/complained)
422recipient_domain_invalidRecipient domain has no MX record
400preflight_failedCampaign validation failed (check issues list)
404not_foundResource not found in this workspace

Worked example

Send a single email and check its status:

# 1. Send an email
curl -s -X POST https://mailwright.tech/backend/v1/emails   -H "Authorization: Bearer mw_live_YOURKEY"   -H "Content-Type: application/json"   -d '{"to": "recipient@example.com", "subject": "Hello there", "body": "Thanks for joining us."}'
# Response: {"id": "log-uuid", "status": "queued", "to": "recipient@example.com", "sender": "you@example.com"}

# 2. Check its status
curl -s https://mailwright.tech/backend/v1/emails/log-uuid   -H "Authorization: Bearer mw_live_YOURKEY"
# Returns status, sent/opened/clicked timestamps, events, and a note about inbox placement.

Rotate and revoke

On the same page, Rotate issues a new secret and Revoke stops the old key. Confirm with your password.

Outbound events

Add an HTTPS endpoint and pick events. Each delivery is JSON.

EventWhen
email.sentThe send was handed off
email.deliveredA delivery event was stored
email.openedThe tracking image loaded
email.clickedA tracked link was opened
email.repliedA reply was stored
email.bouncedA bounce was stored
email.complainedA complaint was stored
email.unsubscribedAn unsubscribe was stored
{
  "id": "event-id",
  "type": "email.sent",
  "created_at": "2026-11-15T00:00:00+00:00",
  "data": {
    "email_id": null,
    "campaign_id": "campaign-id",
    "campaign_name": "Campaign name",
    "channel": "campaign",
    "recipient": "person@example.com",
    "subject": "Subject",
    "sender": "you@example.com",
    "from_email": "you@example.com",
    "bounce_class": null
  }
}

Retries run after 1 minute, 5 minutes, 30 minutes, 2 hours, and 12 hours. The endpoint pauses after 20 failed deliveries.

Verify the signature

Header format: t=<unix>,v1=<hex>. The hex is HMAC-SHA256 of the timestamp, a dot, and the raw body, using the endpoint secret.

Python

import hmac, hashlib
def verify(secret: str, header: str, raw_body: bytes) -> bool:
    parts = dict(piece.split("=", 1) for piece in header.split(",") if "=" in piece)
    signed = f"{parts['t']}.".encode() + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))

Node

const crypto = require("crypto");
function verify(secret, header, rawBody) {
  const parts = Object.fromEntries(header.split(",").map((piece) => piece.split("=")));
  const signed = Buffer.concat([Buffer.from(parts.t + "."), rawBody]);
  const expected = crypto.createHmac("sha256", secret).update(signed).digest("hex");
  const got = parts.v1 || "";
  if (got.length !== expected.length) return false;
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(got));
}

Did this help?

Still stuck? Contact support