Mailrexo API

Read, mark and delete the mail in your inboxes over HTTPS. Requests and responses are JSON.

Base URL https://api.mailrexo.com

Quick start

Every path in these docs is relative to the base URL above. Create an API key on the Developer page of your dashboard, then list the mail of one of your inboxes:

curl "https://api.mailrexo.com/inboxes/hello@mailrexo.com/messages" \
  -H "Authorization: Bearer YOUR_API_KEY"

Replace hello@mailrexo.com with one of your inboxes. The examples read your key from the MAILREXO_API_KEY environment variable, and the language you pick here is used for every example on this page.

All endpoints

Authentication

There are two ways in, and they reach different inboxes.

API key (account inboxes)

Send your key in the Authorization header. A key reaches only the inboxes of its own account, and your plan must include API access.

Authorization: Bearer YOUR_API_KEY

Each key can be limited in the dashboard:

  • Scopes: read allows GET. write allows POST, PATCH and DELETE.
  • Allowed IPs: when set, requests from any other IP get a 403.
  • Expiry: an expired or revoked key gets a 401.

A suspended account loses API access, and its keys get a 403.

Keep your key on your server. The API allows browser requests (CORS), but a key placed in front-end code can be read by anyone who opens the page. A key in the URL is ignored.

Site key (free inboxes)

A website's server can read free inboxes by sending its private site key:

X-Site-Key: YOUR_SITE_KEY
  • It reaches any live free inbox, and it can't reach account inboxes. Free inboxes are public: the address alone opens one.
  • It works from servers only. Browsers can't send this header to the API.
  • If a request has both headers, the site key is used and the API key is ignored.

Rate limits

Limits apply to each API key, counted over the last 60 seconds.

PlanRequests per minute
Premium100
Pro1,000
Business10,000

Requests with a valid key carry these headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 99

Over the limit, the API answers 429 with a Retry-After: 60 header.

Separately, an IP that sends 20 invalid API keys within 10 minutes gets a 429 on every API key request until those attempts age out.

Responses

Every response is JSON with a success field. Check it together with the HTTP status.

{
  "success": false,
  "error": "Your API key can only access your own inboxes."
}

Dates are strings in the form 2026-11-05 09:12:44, in server time with no time-zone offset. To measure how old something is, use age or expires_in, which are in seconds.

List inboxes

GET/inboxes

Returns every inbox of your account, newest first, including expired ones that haven't been cleaned up yet. Needs an API key: a site key gets a 403, because free inboxes can't be listed.

Request

curl "https://api.mailrexo.com/inboxes" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "inboxes": [
    {
      "address": "hello@mailrexo.com",
      "label": "Signup tests",
      "created_at": "2026-11-05 09:12:44",
      "expires_at": "2026-12-05 09:12:44",
      "expires_in": 2591210,
      "active": true,
      "total": 12,
      "unread": 3
    }
  ]
}
FieldTypeDescription
addressstringThe inbox address. Use it in the other endpoints.
labelstringThe name you gave the inbox in the dashboard.
expires_inintegerSeconds until the inbox expires. 0 once it has.
activebooleanfalse for an expired inbox. Its other endpoints answer 410.
totalintegerMessages in the inbox, not counting trash.
unreadintegerUnread messages, not counting trash.

Create inboxes

POST/inboxes

Creates one inbox, or several with random names, ready to receive mail at once. Needs an API key with the write scope. Handy for giving every test run a fresh address.

Body

  • domainstringrequired

    One of our premium domains (such as vip.mailrexo.com; your dashboard's create-inbox form lists them all), or one of your verified custom domains with catch-all turned on. Free public domains can't be used.

  • usernamestringoptional

    The part before the @, for one inbox: letters, numbers, dots, hyphens and underscores, up to 64. Left out, a random name is used.

  • prefixstringoptional

    Start of the random names, for example ci gives ci-4ba816@…. Can't be sent with username.

  • countintegeroptional

    How many inboxes to create, from 1 (the default) to 50. Premium creates one per request; Pro and Business up to 50. More than one needs random names, so no username. Active inboxes are capped per plan: Premium 100, Pro 1,000, Business unlimited (fair use).

  • labelstringoptional

    Its name in the dashboard, up to 90 characters. Defaults to API inbox. With count above 1, each gets a number: Run 1, Run 2…

  • retentionintegeroptional

    Days until the inbox expires: 7, 14, 30 (the default), 90 or 180, up to your plan's limit (Premium 30, Pro 90, Business 180).

Request

curl -X POST "https://api.mailrexo.com/inboxes" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"domain": "vip.mailrexo.com", "prefix": "ci", "retention": 7}'

Response 201

{
  "success": true,
  "inboxes": [
    {
      "address": "ci-4ba816@vip.mailrexo.com",
      "label": "API inbox",
      "created_at": "2026-11-15 13:52:07",
      "expires_at": "2026-11-22 13:52:07",
      "expires_in": 604800,
      "active": true,
      "total": 0,
      "unread": 0
    }
  ]
}

inboxes is always a list, in the order they were created, with the fields of List inboxes. A taken username gets a 409, and a plan limit a 403.

As in the dashboard, each new inbox sends the inbox.created webhook (Pro and Business) and is written to the audit log (Business), with your API key as the actor. Inboxes created here join an All my inboxes forwarding rule right away.

Delete an inbox

DELETE/inboxes/{address}

Permanently deletes one of your inboxes with all its messages and attachments. It works on expired inboxes too. Needs an API key with the write scope.

An address on a Mailrexo domain stays reserved for your account, so nobody else can take it. You can create it again later with username. An address on your custom domain is released.

Path parameters

  • addressstringrequired

    The full email address of the inbox.

Request

curl -X DELETE "https://api.mailrexo.com/inboxes/ci-4ba816@vip.mailrexo.com" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "address": "ci-4ba816@vip.mailrexo.com",
  "deleted": 3
}

deleted is the number of messages removed. Deleting sends the inbox.deleted webhook and is written to the audit log, as in the dashboard.

List messages

GET/inboxes/{address}/messages

Returns the latest 200 messages of an inbox that match the filters, newest first, with a short preview of each. Read one message in full with Read a message.

Messages moved to trash in the dashboard, by hand or by a rule, are left out.

Path parameters

  • addressstringrequired

    The full email address of the inbox. URL-encode it when you build the path in code.

Query parameters

  • sinceinteger | stringoptional

    A message id: only messages with a higher id, so only mail that arrived after it. Or a date like 2026-11-05 09:12:44 in server time: only messages received at or after it. Ids are the safer cursor, since two messages can arrive in the same second.

  • unreadbooleanoptional

    1 returns only unread messages. 0 or leaving it out returns all.

Request

curl "https://api.mailrexo.com/inboxes/hello@mailrexo.com/messages" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "email_created": "2026-11-05 09:12:44",
  "expires_in": 85210,
  "emails": [
    {
      "id": 1842,
      "email_date": "2026-11-05 09:20:03",
      "sender": "no-reply@example.com",
      "sender_name": "Example",
      "recipient": "hello@mailrexo.com",
      "subject": "Your sign-in code",
      "is_read": 0,
      "age": 95,
      "shortBody": "Use 482913 to finish signing in. The code works for 10 minutes.",
      "code": "482913"
    }
  ],
  "msg": null
}
FieldTypeDescription
email_createdstringWhen the inbox was created.
expires_inintegerSeconds until the inbox expires. Never below 0.
emailsarrayThe messages. See Message fields.
msgstring | null"No email messages found." when emails is empty, otherwise null.

Waiting for new mail

To wait for one email in a test, remember the highest id you have seen (or 0), then repeat this request every few seconds until emails isn't empty. With since, each call returns only the new mail:

curl "https://api.mailrexo.com/inboxes/hello@mailrexo.com/messages?since=1842" \
  -H "Authorization: Bearer YOUR_API_KEY"

Polling every 3 seconds uses about 20 requests a minute per inbox. On Pro and Business, the email.received webhook tells you the moment mail arrives, so you don't need to poll at all.

Delete all messages

DELETE/inboxes/{address}/messages

Permanently deletes every message of an inbox, with its attachments.

  • Account inbox: the inbox stays, empty.
  • Free inbox: the inbox is deleted too. Later requests for it get a 410.

Path parameters

  • addressstringrequired

    The full email address of the inbox.

Request

curl -X DELETE "https://api.mailrexo.com/inboxes/hello@mailrexo.com/messages" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "deleted": 12
}

deleted is the number of messages removed.

Read a message

GET/messages/{id}

Returns one message in full, including its text and HTML bodies. {id} comes from the list.

With an API key, reading leaves is_read as it is. With a site key, reading also marks the message as read.

Path parameters

  • idintegerrequired

    The message id from List messages. A positive integer.

Request

curl "https://api.mailrexo.com/messages/1842" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "email": {
    "id": 1842,
    "created_at": "2026-11-05 09:20:05",
    "email_date": "2026-11-05 09:20:03",
    "sender": "no-reply@example.com",
    "sender_name": "Example",
    "recipient": "hello@mailrexo.com",
    "subject": "Your sign-in code",
    "body_text": "Use 482913 to finish signing in. The code works for 10 minutes.",
    "body_html": "<p>Use <b>482913</b> to finish signing in. The code works for 10 minutes.</p>",
    "attachments": [
      {
        "filename": "invoice.pdf",
        "size": 48213,
        "stored": "9f2b6c1e4a7d03f58e1b2c6d-1842_invoice.pdf"
      }
    ],
    "is_read": 0,
    "age": 95,
    "code": "482913",
    "links": [
      "https://example.com/verify?token=7f3a9c"
    ]
  }
}
Treat body_html as untrusted. It's the sender's HTML, unchanged. Sanitize it or show it in a sandboxed iframe, never directly in your page.

Download an attachment

GET/messages/{id}/attachments/{filename}

Returns the file itself, not JSON, as application/octet-stream with a Content-Disposition: attachment header that carries its name. Errors are JSON as usual.

Path parameters

  • idintegerrequired

    The message id.

  • filenamestringrequired

    The filename of one entry in the message's attachments, URL-encoded.

Request

curl -OJ "https://api.mailrexo.com/messages/1842/attachments/invoice.pdf" \
  -H "Authorization: Bearer YOUR_API_KEY"

-OJ saves the file under its own name. A name that isn't on the message, or a file that's no longer on the server, gets a 404.

Attachments come from strangers. Scan them before you open them, and never serve them from your own site as HTML.

Mark read or unread

PATCH/messages/{id}

Send a JSON body with the field is_read: true for read, false for unread.

Path parameters

  • idintegerrequired

    The message id. A positive integer.

Body

  • is_readbooleanrequired

    true marks the message as read, false as unread.

Request

curl -X PATCH"https://api.mailrexo.com/messages/1842" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"is_read": true}'

Response 200

{
  "success": true,
  "id": 1842,
  "is_read": true
}

A missing or invalid is_read gets a 422.

Delete a message

DELETE/messages/{id}

Permanently deletes one message and its attachments.

Path parameters

  • idintegerrequired

    The message id. A positive integer.

Request

curl -X DELETE "https://api.mailrexo.com/messages/1842" \
  -H "Authorization: Bearer YOUR_API_KEY"

Response 200

{
  "success": true,
  "id": 1842
}

Message fields

The In column says where a field appears: in both responses, only in List messages (List), or only in Read a message (Full).

FieldTypeInDescription
idintegerBothThe message id.
email_datestringBothThe date of the email. The list is sorted by this field.
senderstringBothThe sender's address.
sender_namestringBothThe sender's display name.
recipientstringBothThe inbox address.
subjectstringBothThe subject line.
is_readintegerBoth1 for read, 0 for unread. The PATCH response returns a boolean instead.
ageintegerBothSeconds since the message arrived.
codestring | nullBothThe first standalone number of 4 to 8 digits in the subject or body, which is often a verification code. It's a best guess. The list only checks the first 100 or so characters of the body, so the two responses can differ.
shortBodystringListThe first 100 characters of the text body, with ... added if it's longer.
created_atstringFullWhen Mailrexo received the message.
body_textstringFullThe text body.
body_htmlstringFullThe HTML body, unchanged from the sender.
attachmentsarrayFullOne object per attachment, or empty. filename is the file's name, size is its size in bytes (0 if the file can't be found) and stored is its name on the server. Get the file with Download an attachment.
linksarrayFullUp to 50 unique http and https links: those in the HTML body first, then those in the text body. Handy for verification and sign-in links.

Errors

Errors have "success": false and an error message. Messages are for people reading logs, so branch on the HTTP status.

StatusMeaningWhat to do
400The address or message id isn't valid, or a query parameter (since, unread) is. Ids are positive integers.Fix the path or the query.
401The API key is missing, invalid, revoked or expired.Check the Authorization header, or create a new key.
403The key is valid but not allowed: it's read-only, the IP isn't on its list, the plan has no API access, the account is suspended, or the inbox belongs to another account. A wrong site key also gets a 403, and so does a site key on GET /inboxes.Read the error message. Retrying won't help.
404The endpoint, the message or the attachment doesn't exist.Check the path, id and filename. The message may be deleted.
405That method isn't available on this path.Use a method from the Allow response header.
410The inbox has expired. With a site key, the free inbox may also never have existed.Stop polling this address.
409The username you asked for is already in use.Pick another, or leave it out for a random name.
422The JSON body is invalid: a missing or wrong is_read, or a field of Create inboxes, such as a domain you can't use.Read the error message and fix the body.
429Rate limit reached, or too many invalid keys from your IP.Wait, then retry. See Rate limits.
500Something failed on our side.Retry after a short wait.