Mailrexo API
Read, mark and delete the mail in your inboxes over HTTPS. Requests and responses are JSON.
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
- GET/inboxesList inboxes
- POST/inboxesCreate inboxes
- DELETE/inboxes/{address}Delete an inbox
- GET/inboxes/{address}/messagesList messages
- DELETE/inboxes/{address}/messagesDelete all messages
- GET/messages/{id}Read a message
- GET/messages/{id}/attachments/{filename}Download an attachment
- PATCH/messages/{id}Mark read or unread
- DELETE/messages/{id}Delete a message
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:
readallowsGET.writeallowsPOST,PATCHandDELETE. - 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.
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.
| Plan | Requests per minute |
|---|---|
| Premium | 100 |
| Pro | 1,000 |
| Business | 10,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
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
}
]
}| Field | Type | Description |
|---|---|---|
address | string | The inbox address. Use it in the other endpoints. |
label | string | The name you gave the inbox in the dashboard. |
expires_in | integer | Seconds until the inbox expires. 0 once it has. |
active | boolean | false for an expired inbox. Its other endpoints answer 410. |
total | integer | Messages in the inbox, not counting trash. |
unread | integer | Unread messages, not counting trash. |
Create 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
domainstringrequiredOne 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.usernamestringoptionalThe part before the
@, for one inbox: letters, numbers, dots, hyphens and underscores, up to 64. Left out, a random name is used.prefixstringoptionalStart of the random names, for example
cigivesci-4ba816@…. Can't be sent withusername.countintegeroptionalHow many inboxes to create, from
1(the default) to50. Premium creates one per request; Pro and Business up to 50. More than one needs random names, so nousername. Active inboxes are capped per plan: Premium 100, Pro 1,000, Business unlimited (fair use).labelstringoptionalIts name in the dashboard, up to 90 characters. Defaults to
API inbox. Withcountabove 1, each gets a number:Run 1,Run 2…retentionintegeroptionalDays until the inbox expires:
7,14,30(the default),90or180, 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
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
addressstringrequiredThe 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
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
addressstringrequiredThe full email address of the inbox. URL-encode it when you build the path in code.
Query parameters
sinceinteger | stringoptionalA message id: only messages with a higher id, so only mail that arrived after it. Or a date like
2026-11-05 09:12:44in server time: only messages received at or after it. Ids are the safer cursor, since two messages can arrive in the same second.unreadbooleanoptional1returns only unread messages.0or 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
}| Field | Type | Description |
|---|---|---|
email_created | string | When the inbox was created. |
expires_in | integer | Seconds until the inbox expires. Never below 0. |
emails | array | The messages. See Message fields. |
msg | string | 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
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
addressstringrequiredThe 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
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
idintegerrequiredThe 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"
]
}
}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
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
idintegerrequiredThe message id.
filenamestringrequiredThe
filenameof one entry in the message'sattachments, 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.
Mark read or unread
Send a JSON body with the field is_read: true for read, false for unread.
Path parameters
idintegerrequiredThe message id. A positive integer.
Body
is_readbooleanrequiredtruemarks the message as read,falseas 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
Permanently deletes one message and its attachments.
Path parameters
idintegerrequiredThe 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).
| Field | Type | In | Description |
|---|---|---|---|
id | integer | Both | The message id. |
email_date | string | Both | The date of the email. The list is sorted by this field. |
sender | string | Both | The sender's address. |
sender_name | string | Both | The sender's display name. |
recipient | string | Both | The inbox address. |
subject | string | Both | The subject line. |
is_read | integer | Both | 1 for read, 0 for unread. The PATCH response returns a boolean instead. |
age | integer | Both | Seconds since the message arrived. |
code | string | null | Both | The 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. |
shortBody | string | List | The first 100 characters of the text body, with ... added if it's longer. |
created_at | string | Full | When Mailrexo received the message. |
body_text | string | Full | The text body. |
body_html | string | Full | The HTML body, unchanged from the sender. |
attachments | array | Full | One 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. |
links | array | Full | Up 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.
| Status | Meaning | What to do |
|---|---|---|
| 400 | The address or message id isn't valid, or a query parameter (since, unread) is. Ids are positive integers. | Fix the path or the query. |
| 401 | The API key is missing, invalid, revoked or expired. | Check the Authorization header, or create a new key. |
| 403 | The 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. |
| 404 | The endpoint, the message or the attachment doesn't exist. | Check the path, id and filename. The message may be deleted. |
| 405 | That method isn't available on this path. | Use a method from the Allow response header. |
| 410 | The inbox has expired. With a site key, the free inbox may also never have existed. | Stop polling this address. |
| 409 | The username you asked for is already in use. | Pick another, or leave it out for a random name. |
| 422 | The 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. |
| 429 | Rate limit reached, or too many invalid keys from your IP. | Wait, then retry. See Rate limits. |
| 500 | Something failed on our side. | Retry after a short wait. |