Skip to main content
curl 'https://api.mails.ai/v1/messages/received/wait' \
  -H "Authorization: Bearer $MAILS_API_KEY"
{
  "message": {
    "id": "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "agent_id": "agt_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "thread_id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "from": {
      "address": "jordan@example.com",
      "name": "<name>"
    },
    "envelope_from": "<envelope_from>",
    "to": "jordan@example.com",
    "subject": "<subject>",
    "is_thread_reply": false,
    "in_reply_to_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "thread_root_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "body_text": "<body_text>",
    "body_html": "<body_html>",
    "body_text_excerpt": "<body_text_excerpt>",
    "extracted_text": "<extracted_text>",
    "extracted_html": "<extracted_html>",
    "codes": [{ "value": null }],
    "links": [{ "url": null, "kind": null }],
    "spf_pass": false,
    "dkim_pass": false,
    "dkim": "pass",
    "dkim_domain": "<dkim_domain>",
    "dmarc": "pass",
    "auth_failed": false,
    "has_attachment": false,
    "attachments": [
      {
        "id": null,
        "filename": null,
        "content_type": null,
        "size": null,
        "content_id": null,
        "inline": null
      }
    ],
    "attachments_omitted": [
      {
        "filename": null,
        "content_type": null,
        "size": null,
        "reason": null
      }
    ],
    "attachments_omitted_count": 0,
    "raw_omitted": "too_large",
    "over_limit": "quota_exceeded",
    "parse_status": "parsed",
    "injection_score": 0,
    "quarantined": false,
    "received_at": "2026-10-04T12:00:00.000Z",
    "raw_url": "<raw_url>",
    "created_at": "2026-10-04T12:00:00.000Z"
  },
  "timed_out": false
}

Wait for a received message

Answers with the newest received message that matches, holding on for up to timeout seconds until one arrives.
GET/v1/messages/received/waitscope · read
curl 'https://api.mails.ai/v1/messages/received/wait' \
  -H "Authorization: Bearer $MAILS_API_KEY"
{
  "message": {
    "id": "rcv_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "agent_id": "agt_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "thread_id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "from": {
      "address": "jordan@example.com",
      "name": "<name>"
    },
    "envelope_from": "<envelope_from>",
    "to": "jordan@example.com",
    "subject": "<subject>",
    "is_thread_reply": false,
    "in_reply_to_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "thread_root_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
    "body_text": "<body_text>",
    "body_html": "<body_html>",
    "body_text_excerpt": "<body_text_excerpt>",
    "extracted_text": "<extracted_text>",
    "extracted_html": "<extracted_html>",
    "codes": [{ "value": null }],
    "links": [{ "url": null, "kind": null }],
    "spf_pass": false,
    "dkim_pass": false,
    "dkim": "pass",
    "dkim_domain": "<dkim_domain>",
    "dmarc": "pass",
    "auth_failed": false,
    "has_attachment": false,
    "attachments": [
      {
        "id": null,
        "filename": null,
        "content_type": null,
        "size": null,
        "content_id": null,
        "inline": null
      }
    ],
    "attachments_omitted": [
      {
        "filename": null,
        "content_type": null,
        "size": null,
        "reason": null
      }
    ],
    "attachments_omitted_count": 0,
    "raw_omitted": "too_large",
    "over_limit": "quota_exceeded",
    "parse_status": "parsed",
    "injection_score": 0,
    "quarantined": false,
    "received_at": "2026-10-04T12:00:00.000Z",
    "raw_url": "<raw_url>",
    "created_at": "2026-10-04T12:00:00.000Z"
  },
  "timed_out": false
}

Query Parameters

agent_idstring

Filter by agent id or name. A key tied to one agent always reads that agent's mail, and naming another agent is a 403.

fromstring

Only mail from this sender: an address (noreply@github.com, in any case) or a domain (github.com, which takes its subdomains such as mail.github.com and never github.com.evil.example). It is the From header's address, proven only when the message's dmarc is pass. Anything else answers 400 invalid_param_value.

sincestring

Only mail received at or after this time: an ISO 8601 time such as 2026-10-05T07:00:00Z, or a date (midnight UTC). Any other value answers 400 invalid_param_value. Default: the last 5 minutes. Pass the time you asked the service to send, so an older code never answers.

hasstring

code: only a message with at least one entry in codes. link: only one with a verify, sign_in or reset_password link. Absent: any message that matches the other filters.

One of: code, link

timeoutinteger

Seconds to wait for a match, 0 to 50 (default 30). 0 looks once and answers at once.

Made for an agent that has just asked a service for a sign-up code, a magic link or a password reset: name the sender with from and what you need with has, then read message.codes[0].value or the first message.links entry. Mail judged forged (auth_failed) and quarantined mail never match. Nothing in time is not an error: message is null and timed_out true.

Response

messageobject | null

The newest matching message, or null when none arrived in time.

timed_outboolean

True when the wait ended without a match.

Was this page helpful?