Skip to content

Receive and read email

Your test sends something that triggers an email; the next step needs that email. GET /v0/messages/wait (MCP: wait_for_message) answers the moment a matching message arrives — no polling loop, no sleeping.

Terminal window
curl -s -G https://api.yoagent.dev/v0/messages/wait \
-H "Authorization: Bearer $YOAGENT_KEY" \
--data-urlencode "to=signup@k7m2xq4p.yoagent.email" \
--data-urlencode "subject=Confirm your email" \
--data-urlencode "timeout=60"
Parameter What it does
to or inbox_id Exactly one. to is the address the mail was sent to — a plus address or an address the catch-all takes works too; inbox_id waits for any mail of an inbox.
from (MCP: sender), subject Part of the sender’s address or name, part of the subject, in any case. A welcome email that arrives first does not stop a wait for the confirmation.
after Only mail received after this time, by the API’s clock. Default: 5 minutes before the call. Pass the time your test started — or the inbox’s created_at — so an older email never passes for this one.
timeout Seconds to wait. REST: 30 seconds by default, at most 2 minutes; MCP: 45 seconds by default, at most 55 seconds.
cursor The cursor of the previous answer: the next message after that one, with the same after.

The answer is {"message": …, "cursor": "…"}, with the earliest matching message received after after — not the newest. When nothing arrived in time, message is null: wait again with the cursor, or fail the test. To read several messages in turn — a welcome email, then a confirmation — call again with each answer’s cursor. A wait returns only mail that came in, never the inbox’s own sent copies.

Mail is matched as it is stored, so it does not matter whether the email arrives before or after the call starts.

GET /v0/messages/{message_id} (MCP: get_message) returns the message whole. The fields a test usually needs:

Field What it is
subject, from, to, cc The headers, with each party as { "name", "address" }
text, html The body as sent
extracted_text The body without the quoted earlier messages of a reply: what this message itself says
links The links in the body: { "url", "text", "kind" }, with kind one of verify, reset, unsubscribe, other
codes Codes found in the subject and body, such as a sign-in code: { "code", "context" }
attachments { "attachment_id", "filename", "content_type", "size", "download_url" }
envelope_to, plus_tag The address the mail was really sent to, and its +tag when it came through a plus address
labels received, unread and the others (Threads, labels and search)

Reading a message over the API does not mark it read; the dashboard does when someone who may change its labels opens it.

Over MCP, get_message keeps the answer small for the agent’s context: it leaves out the HTML and the headers unless you pass include_html=true, and cuts each body field to 20,000 characters. The fields it cut are listed in truncated; over REST nothing is cut, and truncated is empty. The links and the codes alone: extract_links and extract_codes (REST: GET /v0/messages/{message_id}/links and …/codes).

A received message in the dashboard: its sender, text, the confirmation link and code

  • An attachment: GET /v0/messages/{message_id}/attachments/{attachment_id} — its download_url — returns the file as application/octet-stream.
  • The raw message: GET /v0/messages/{message_id}/raw returns it exactly as it arrived, as message/rfc822 (message.eml).

Both are REST downloads and need an API key. An agent connected by OAuth sees an attachment’s name, type and size, but downloads it with an API key.

A message gets the label unauthenticated when nothing proves its From address: no DKIM signature of that domain and no SPF pass for it. It is still delivered — many test senders are unauthenticated — but an agent should not trust what such a message claims about who wrote it. Mail between YoAgent inboxes counts as authentic.

Everything in a message came from its sender: the subject, the text, the names, the links. Over MCP every answer lists such fields in meta.untrusted_fields, so an agent can tell your instructions from an email’s: it should report what an email says, never do what it says.

The sending server gets an SMTP answer while it is still connected, so the sender learns at once:

Answer Why
550 5.1.1 No such user here No inbox has that address, and no plus address or catch-all takes it; or the domain is not verified
552 (message size) The message is over 10 MB, attachments included
452 4.2.2 Daily limit of received messages reached for this YoAgent organization Your plan’s received messages a day are used up, or one sending server sent its share (100 a day); the sender’s server tries again later
451 4.7.1 Too many recipients from your address; try again in a minute One sending server gave more than 60 recipients in a minute; it tries again

A 4xx answer is temporary: a mail server keeps the message and tries again, so nothing is lost. Code that talks SMTP itself must retry on its own.