Skip to main content
mailers.io

API and MCP

Send and track e-mail from code with the mailers.io API

By mailers.io team Published 5 min read

You have an application that must send e-mail: a receipt, a password reset, a notice, a batch of messages to your own users. You want to hand the message to code and learn what happened to it. This guide shows the path through the mailers.io API, from the key to reading results, and is open about where it stops. The full reference, with every field, is at docs.mailers.io.

What the API is, and what it sends through

The API does not send mail itself. A message goes to the sending servers you connected to your account (Amazon SES, SendGrid, Mailgun, Gmail and the others), and the routing described in routing by provider quota and speed limits picks one. If the first server fails, the message moves to another one. Your calls look the same either way.

That has a consequence worth stating once. Delivery depends on your servers, your domains and your list. The API makes sending convenient. It does not make poor sending good.

Get a key

Create an API key in your account. Keys begin with mio_live_, carry scopes, can expire and can be revoked. Send it as a bearer token:

Authorization: Bearer mio_live_...

For sending and reading results you need two scopes: send for POST /messages and messages.read for the read calls. A key never works as a browser login, and every id you can see belongs to the key’s account. API access is on all current plans. Use one key per application, so you can revoke one without touching the rest.

The base URL and the OpenAPI file are in the developer documentation.

Send one message

POST /api/v3/messages takes JSON. from, to and subject are required, plus a body. The body is either text and/or html, or a template_id of one of your own templates, never both.

POST /api/v3/messages
Authorization: Bearer mio_live_...
Idempotency-Key: order-1042-receipt
Content-Type: application/json

{
  "from": "[email protected]",
  "from_name": "Your Company",
  "to": ["[email protected]"],
  "subject": "Your receipt",
  "text": "Thanks for your order."
}

Some details that matter:

  • The from address must be one that your sending server is allowed to use. With Amazon SES, for example, it must belong to a verified identity.
  • to, cc and bcc take up to 50 addresses each. Every recipient gets their own copy, addressed only to them. No Cc header is added, so recipients do not see each other.
  • reply_to and from_name are optional.
  • Opens and clicks are not tracked by default. Set track_opens or track_clicks to true if you want them. Opens by mail clients that load images on their own are flagged and not counted as unique opens, so do not treat open rates as exact.

The answer is a 202. It lists one queued message per recipient, with an id, and lists any recipient that was skipped as suppressed. A suppressed address is not sent to and not charged. Each queued recipient uses one credit.

Retry without sending twice

A network error after you sent a request leaves you not knowing whether the message was queued. Add the Idempotency-Key header, a string of 1 to 255 characters that you choose, for example from your order id.

  • The same key with the same body within 24 hours returns the first answer again, with the header Idempotent-Replayed: true. Nothing is queued twice.
  • The same key with a different body is a 409.

Build your retry loop on this. Retry on network errors and on 429, which comes with a Retry-After header: wait that many seconds. Do not retry a 400 without changing the request, and treat 402 as a signal that your credits ran out. The error body is { "error": { "code", "message", "fields" } }, so you can show the field that was wrong.

Read the result

Queued is not delivered. To see what happened, use:

  • GET /api/v3/messages/{id} for one message. It has the status (queued, sending, sent, failed, deferred or skipped), whether it was charged, the list of attempts with the SMTP or provider code and error, and the events.
  • GET /api/v3/messages for a list. It needs from and to as date-times, and pages of 25, 50 or 100.

The events are delivered, bounce_hard, bounce_soft and complaint. A hard bounce or a complaint also puts the address on the suppression list, so later sends to it are skipped.

The attempts are useful when something goes wrong. If your first server was full or failing, the message shows each server that was tried and what it answered, because a message can go through up to three servers by default.

Webhooks, which would push these events to your own URL, are not part of current plans. Today you fetch them with the read calls. Poll a message a few times with a growing pause, instead of in a tight loop, and keep an eye on the rate limit.

Rate limits

The default is 600 requests per minute per account, and each key has its own limit too. Over it you get a 429 with Retry-After. If your own volume is high, spread the calls. It is also worth leaving headroom for reads, because they count against the same limit.

Bulk mail

A common question is how to send to thousands of people. The honest answer depends on the kind of mail.

  • Transactional mail, one message because of one event: call POST /messages for each, with an idempotency key. That is what the endpoint is for.
  • A campaign to a list, such as a newsletter: use a campaign in the app. There is no campaign endpoint in the API, and no endpoint for credits or balance.
  • Outreach: use a sequence. The cold e-mail API post covers adding contacts and enrolling them.

You can also keep your audience in step with your application. The API can create lists, add contacts, update or unsubscribe them, and relay a sign-up or an unsubscribe a person made on your own page. Those calls are in the reference.

Looping POST /messages over a long list is allowed, but each call is one request against your limit, and you lose what a campaign gives you: the unsubscribe handling, the report and the pacing. If it is a mailing, use a campaign.

SMTP and MCP as alternatives

If your software already speaks SMTP, you can point it at the SMTP relay with a key of the SMTP kind and change nothing else. The MCP endpoint exposes the same API as tools to an AI assistant, filtered by the key’s scopes.

Checklist before going live

  1. A key with only send and messages.read, stored as a secret in your app and never in front-end code.
  2. A from address on a domain you have verified with DKIM.
  3. An idempotency key on every send.
  4. Retries that respect Retry-After.
  5. A read of GET /messages/{id} in a test, to see that your attempts and events look as you expect.
  6. Two sending servers, so that a failure at one does not stop you.

Then read the reference for every field and error, and the API overview for what is in each plan.

Questions and answers

Is there a call that sends one message to a whole list?

No. A request takes up to 50 recipients in each of to, cc and bcc, and each gets their own copy. For a list, run a campaign in the app.

How do I know a message was delivered?

Read it back with GET /messages/{id}. It returns each attempt and the events, such as delivered, bounce_hard, bounce_soft or complaint.

Is there an SDK?

No. The API is plain HTTP with an OpenAPI 3.1 spec.

Written by the mailers.io team. Published .

Keep reading

Related posts

Send cold e-mail from your own servers.

Connect your servers, import a list and write the steps. Replies stop the sequence.

  • 7-day money-back guarantee
  • Bring your own providers
  • Cancel anytime