Build with AI

AI Onboarding

Everything you need to onboard your AI agent to MailBlastr — the MCP server, docs for agents, the Chat SDK, and production best practices.

If you are building with AI, MailBlastr offers several resources to improve your experience — an MCP server, agent-readable docs, an email Chat SDK, and battle-tested best practices for production sends. This page is the jumping-off point.

Prerequisite: create an API key

We require a human to create a MailBlastr account. Once you have an account, create an API key — it looks like mb_xxxxxxxxx. With a key, your agent can send email and manage most of your account over the API.

To send from MailBlastr you also need a verified domain. An agent can create a domain via the API, but the response returns DNS records you must add at your DNS provider before verifying. Verifying in the dashboard is usually easier.

MailBlastr MCP server

MCP is an open protocol that standardizes how applications provide context to LLMs. Among other benefits, it gives LLMs tools to act on your behalf. The MailBlastr MCP server is published on NPM as mailblastr-mcp and covers the full API surface. Add it to any supported MCP client:

{
  "mcpServers": {
    "mailblastr": {
      "command": "npx",
      "args": ["-y", "mailblastr-mcp"],
      "env": {
        "MAILBLASTR_API_KEY": "mb_xxxxxxxxx"
      }
    }
  }
}

See MCP Server for install instructions for Cursor, Codex, Claude Desktop, Windsurf, and more.

MailBlastr docs for agents

You can give your agent current, context-aware docs in two ways:

  1. Markdown docs — every doc page has a Markdown version. Append .md to any page URL, e.g. https://mailblastr.com/docs/ai/onboarding.md.
  2. MCP docs server — for a structured approach using MCP tools, point your client at the docs MCP endpoint so your agent can search the docs as tools rather than fetching a single large file.

Email skills for agents

Skills give AI agents specialized knowledge for specific tasks. These are reference *patterns* you capture as a SKILL.md (or equivalent context file) in your repo — they build on the `mailblastr` SDK, the `mailblastr-mcp` MCP server, webhooks, and native HTTP, so there is nothing extra to install:

SkillWhat it does
MailBlastrSend and receive emails, handle errors, prevent duplicate sends, and get code examples.
React EmailBuild emails in React, Tailwind, and TypeScript; audit existing React emails for style and cross-client rendering.
Email Best PracticesAudit SPF/DKIM/DMARC setup, compliance (CAN-SPAM, GDPR), and webhook handling.
Agent Email InboxGive an agent a secure inbox to receive and act on inbound email.

Conversational email (Chat SDK pattern)

You can turn email into a two-way communication channel for an agent: send replies with the `mailblastr` SDK or POST /emails, receive inbound mail through webhooks (email.received), and thread conversations with standard In-Reply-To/References headers. The Chat SDK guide shows how to wire this up as a Vercel Chat SDK adapter, including card emails, attachments, and proactive outreach.

Quick start: sending email from an agent

MailBlastr provides two endpoints for sending. Pick the right one for the job:

ApproachEndpointUse case
SinglePOST /emailsIndividual transactional emails, emails with attachments, scheduled sends.
BatchPOST /emails/batchMultiple distinct emails in one request (max 100), bulk notifications.

Choose batch when you are sending 2+ distinct emails at once and want to reduce API calls. Choose single when you are sending one email, the email needs attachments, the email needs to be scheduled, or different recipients need different timing.

Best practices (critical for production)

Always implement these for production email sending.

Idempotency keys — prevent duplicate emails when retrying failed requests. Pass a unique Idempotency-Key header per logical send; a retry with the same key replays the original response instead of sending again. See Idempotency keys.

Key facts
Format (single)<event-type>/<entity-id> (e.g. welcome-email/user-123)
Format (batch)batch-<event-type>/<batch-id> (e.g. batch-orders/batch-456)
Expiration24 hours
Max length256 characters
Duplicate payloadReturns the original response without resending
Different payloadReturns a 409 error

Error handling — map status codes to actions:

CodeAction
400 / 422Fix request parameters — do not retry.
401 / 403Check your API key / verify your domain — do not retry.
409Idempotency conflict — an identical key is still in flight. Wait and retry, or use a fresh key.
429Rate limited — retry with exponential backoff.
500Server error — retry with exponential backoff.

Retry strategy — use exponential backoff (1s, 2s, 4s…), cap at 3–5 retries, only retry 429 and 500, and always send the same idempotency key on a retry.

Single send parameters

Required
fromstringrequired

Sender address. Format: "Name <email@domain.com>" (must be on a verified domain).

tostring[]required

Recipient addresses (max 50).

subjectstringrequired

Email subject line.

html / textstringrequired

Email body content (provide at least one).

Optional
ccstring[]optional

CC recipients.

bccstring[]optional

BCC recipients.

reply_tostring[]optional

Reply-to addresses.

scheduled_atstringoptional

Schedule send time (ISO 8601 or natural language).

attachmentsarrayoptional

File attachments (max 40MB total).

tagsarrayoptional

Key/value pairs for tracking.

headersobjectoptional

Custom headers.

Minimal single send

curl -X POST 'https://api.mailblastr.com/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: welcome-email/user-123' \
  -d '{
    "from": "Acme <onboarding@yourdomain.com>",
    "to": ["delivered@example.com"],
    "subject": "Hello World",
    "html": "<p>Email body here</p>"
  }'

Minimal batch send

Because a batch is validated atomically — one invalid item rejects the whole request — pre-validate every email (required fields, address format, and a size of 1–100) before sending.

  • No attachments — use single sends for emails with attachments.
  • No scheduling — use single sends for scheduled emails.
  • Atomic — if one email fails validation, the entire batch fails.
  • Max 100 emails per request.
  • Max 50 recipients per individual email in the batch.
import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.batch.send([
  { "from": "Acme <hello@yourdomain.com>", "to": ["a@example.com"], "subject": "Order Shipped",   "html": "<p>Your order has shipped!</p>" },
  { "from": "Acme <hello@yourdomain.com>", "to": ["b@example.com"], "subject": "Order Confirmed", "html": "<p>Your order is confirmed!</p>" }
]);
console.log({ data, error });
See Send an email and Send a batch for the full parameter reference.