The wait API
Tests should not sleep and poll. The wait API holds the request open until what you are waiting for happens, then returns it: an email with its text, its links, any one-time codes and any sign-in links, a person’s reply or action, or a whole conversation.
Every wait needs the viewer role or higher. Waits hold the connection open, so give your HTTP client a timeout a little longer than the wait’s. Every timeout is at most 5m.
| Wait for | Section |
|---|---|
| The next email (or the next few) | Wait for an email |
| No email at all, for a while | Make sure no email arrives |
| A person’s reply | Wait for a reply |
| Something a person does: opens a link, junks you, bounces, promises | Wait for what a person does |
| A conversation to go quiet | Wait until a conversation goes quiet |
Wait for an email
Section titled “Wait for an email”GET /api/wait
Section titled “GET /api/wait”Returns the next email that matches every filter you give.
| Parameter | Default | Meaning |
|---|---|---|
to | The receiving address. Repeat it (or separate addresses with commas) to watch several, or use *@yourcompany.test to watch every mailbox at a domain, including ones that appear while the wait runs. to or tag is required. | |
tag | Every test address made with this tag. | |
from | Part of the sender’s address or name, any case. | |
subject | Words in the subject, any case. | |
contains | Words in the body (text or HTML), any case. | |
subject_regex | A regular expression the subject must match (RE2 syntax; start it with (?i) to ignore case). | |
body_regex | A regular expression the text or HTML must match. | |
header | Name:value: the header must contain the value, any case. Repeat it for several headers. | |
has_attachment | true for mail with an attached file (inline images do not count), false for mail without. | |
attachment_name | Part of an attachment’s file name, such as .pdf or invoice. | |
link_domain | The email links to this host or a subdomain of it, such as app.yourcompany.test. | |
folder | INBOX | The folder to watch, such as Junk or Sent. |
count | 1 | Wait until this many matching emails have arrived (1 to 100). |
since | Only mail after this: an RFC 3339 time, or the message_id of a message simmail holds. Mail already there counts too. | |
exclude | Message-IDs to skip, separated by commas. | |
existing | true also matches messages already there. Otherwise only mail that arrives after the request starts counts (unless you give since). | |
timeout | 30s | How long to wait, as 45s, 2m and so on. |
curl -s -G https://c1.simmail.dev/api/wait \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "subject=verify" \ --data-urlencode "timeout=20s"{ "folder": "INBOX", "uid": 1, "from_name": "Acme", "subject": "Verify your email", "date": "2026-10-10T14:30:00Z", "text": "Your verification code is 482913.\n\nOr click https://app.yourcompany.test/verify?token=abc123", "links": ["https://app.yourcompany.test/verify?token=abc123"], "codes": ["482913"], "magic_links": ["https://app.yourcompany.test/verify?token=abc123"], "waited_ms": 1840, "matched": ["to", "subject"]}waited_ms is how long the wait took, and matched lists the filters the email passed.
With the SDKs:
const msg = await mail.waitForEmail({ to: "[email protected]", subject: "verify", timeout: "20s" });console.log(msg.codes[0], msg.magicLinks[0]);print(msg.codes[0], msg.magic_links[0])Matching more precisely
Section titled “Matching more precisely”# The invoice email, to anyone at the test domain, with a PDF attached,# a link to the billing site and the campaign headercurl -s -G https://c1.simmail.dev/api/wait \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "to=*@yourcompany.test" \ --data-urlencode "subject_regex=(?i)^invoice #\d+" \ --data-urlencode "attachment_name=.pdf" \ --data-urlencode "link_domain=billing.yourcompany.test" \ --data-urlencode "header=X-Campaign:billing"const invoice = await mail.waitForEmail({ to: "*@yourcompany.test", subjectRegex: /^invoice #\d+/i, attachmentName: ".pdf", linkDomain: "billing.yourcompany.test", header: { "X-Campaign": "billing" },});invoice = mail.wait_for_email( "*@yourcompany.test", subject_regex=re.compile(r"^invoice #\d+", re.I), attachment_name=".pdf", link_domain="billing.yourcompany.test", header={"X-Campaign": "billing"},)Waiting for several
Section titled “Waiting for several”With count, the wait returns once that many matching emails have arrived, oldest first:
curl -s -G https://c1.simmail.dev/api/wait \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "subject=weekly digest" \ --data-urlencode "count=2"{ "messages": [ ], "count": 2, "waited_ms": 3120, "matched": ["to", "subject"]}const { messages } = await mail.waitForEmail({ to: ["[email protected]", "[email protected]"], subject: "weekly digest", count: 2 });digests = mail.wait_for_email(["[email protected]", "[email protected]"], subject="weekly digest", count=2)To take the next email after one you have already handled, pass its Message-ID as since, or list the ones to skip in exclude.
When nothing matches
Section titled “When nothing matches”A wait that times out answers 408 with the code wait_timeout and up to five of the most recent emails to the watched addresses that did not match, with the filters each one failed. A failing test explains itself:
{ "error": "no matching message arrived before the timeout", "code": "wait_timeout", "request_id": "req_40d5c947215616d7", "matched": ["to", "subject"], "waited_ms": 20004, "near_misses": [ { "subject": "Welcome to Acme", "received": "2026-10-10T14:30:02Z", "failed": ["subject"] } ]}With count, a timeout also lists the messages that did arrive. The SDKs raise it as WaitTimeoutError, with nearMisses (near_misses in Python).
| Status | Code | Meaning |
|---|---|---|
200 | The email (or, with count, the emails). | |
400 | invalid_regex | subject_regex or body_regex is not a valid regular expression; field says which. |
400 | invalid_value | Another parameter is wrong, such as count outside 1 to 100, a header without a colon, or a since simmail cannot place; field names it. |
400 | bad_request | Neither to nor tag. |
408 | wait_timeout | Nothing matched in time; see near_misses. |
Make sure no email arrives
Section titled “Make sure no email arrives”GET /api/wait/none
Section titled “GET /api/wait/none”Passes when no matching email arrives for a while: no duplicate welcome email, nothing to someone who unsubscribed, no mail after a failed payment. It takes every filter of GET /api/wait (to, tag, from, subject, contains, the regular expressions, header, attachments, link_domain, folder, since, exclude), and:
| Parameter | Default | Meaning |
|---|---|---|
to | One or more addresses, or *@domain. to or tag is required. | |
tag | Every test address made with this tag. | |
subject | Words in the subject, any case. | |
for | 5s | How long nothing may arrive. |
curl -s -G https://c1.simmail.dev/api/wait/none \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "subject=welcome" \ --data-urlencode "for=10s"When nothing came, it answers 200 with {"none": true, "waited_ms": 10002, "matched": ["to", "subject"]}. As soon as a matching email arrives, it answers 409 with the code unexpected_email and the message.
The SDKs raise UnexpectedEmailError (with the email that arrived) instead of returning.
Wait for a reply
Section titled “Wait for a reply”GET /api/wait/reply
Section titled “GET /api/wait/reply”Returns the next email a persona sends.
| Parameter | Default | Meaning |
|---|---|---|
from | required | The persona’s address. |
in_reply_to | Only a reply in this thread: the Message-ID of your email, with its angle brackets. It matches the reply’s In-Reply-To or References. | |
fast | true has the person write their due reply now, instead of on the simulated clock. | |
timeout | 30s | As above. |
curl -s -G https://c1.simmail.dev/api/wait/reply \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "fast=true"The answer has the same fields as above, read from the person’s Sent folder, with by_persona: true.
const reply = await mail.waitForReply({ from: "[email protected]", inReplyTo: "<[email protected]>" }); // fast by defaultreply = mail.wait_for_reply("[email protected]", in_reply_to="<[email protected]>") # fast by defaultWith fast=true, simmail runs the person’s next planned job now, again and again, until a matching email appears. Without it, the person replies when the simulated clock reaches their reply. You can move the clock yourself with POST /api/clock/advance.
| Status | Meaning |
|---|---|
200 | The reply. |
404 | Nobody plays that address. |
408 | No reply before the timeout. |
409 | With fast=true: the person sat down to write and decided not to reply (or their AI is off), and nothing else is planned. Waiting longer would not help. |
A person who chose not to answer at all (their reply rate) plans nothing, so the wait runs to its timeout and ends with 408. The persona.ignored event says why.
Speed up a reply in a test
Section titled “Speed up a reply in a test”Everything people will do later sits in the job queue: replies, follow-ups, out-of-office answers, bounces. A test does not have to wait for the simulated clock: run what is queued for a person now with POST /api/jobs/run-due, then read the result.
curl -s -X POST https://c1.simmail.dev/api/jobs/run-due \ -H "Authorization: Bearer smk_your_key" -H "Content-Type: application/json" \await dana.runDue({ kind: JobKind.Reply }); // or: await mail.runDue({ persona: "[email protected]" })The reply, event and thread waits do this for you with fast=true.
Wait for what a person does
Section titled “Wait for what a person does”GET /api/wait/event
Section titled “GET /api/wait/event”Returns the next event of a kind: a person opening a link, junking your email, bouncing, promising something, replying.
| Parameter | Default | Meaning |
|---|---|---|
type | required | An event kind or a short name from the table below. Several, separated by commas, or a prefix such as persona.*. |
persona | Only events about this person: an id or an address. | |
message_id | Only events about this message (or a reply to it). | |
after | Only events after this event id. By default, only events after the wait starts. | |
fast | With persona: run what that person has queued now, until the event happens. | |
timeout | 30s | As above. |
curl -s -G https://c1.simmail.dev/api/wait/event \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "type=clicked" \ --data-urlencode "fast=true"{ "event": { "id": 4182, "at": "2026-10-10T15:02:00Z", "kind": "link.opened", "data": { "persona": "Dana Reyes", "persona_id": "p_3fa2b1c9d0", "url": "https://app.yourcompany.test/offer/1701", "status": 200 } }, "waited_ms": 640}const click = await dana.waitFor(EventAlias.Clicked, { fast: true });click = dana.wait_for(EventAlias.CLICKED, fast=True)An unknown type answers 400 with the code invalid_value and the allowed kinds. A kind your plan cannot produce answers 402 (not_in_plan) straight away instead of waiting in vain. A wait that times out answers 408 (wait_timeout).
Event kinds
Section titled “Event kinds”| Kind | Short names | What happened | Needs |
|---|---|---|---|
mail.delivered | delivered | Mail your app sent was delivered to its recipients | |
persona.received | received | A person received an email and read it | |
persona.sent | replied, sent | A person sent an email: a reply, a follow-up or a forward | |
persona.ignored | declined, ignored | A person decided not to answer (or their AI is off) | |
persona.batched | A person will answer several emails together | ||
persona.junked | junked | A person’s provider filed your email as spam; they never saw it | Junk consequences |
persona.rescued | rescued | An email was moved from Junk to a person’s inbox | |
persona.bounced | bounced | An address bounced (dead, full, blocked) | |
persona.promised | promised | A person promised to do something | Lifelike behaviour |
persona.waiting | A person is waiting on something you promised | Lifelike behaviour | |
link.opened | clicked, opened_link | A person clicked a link in an email | Lifelike behaviour |
link.skipped | A person chose not to open a link | Lifelike behaviour | |
link.failed | A person clicked a link and it failed | Lifelike behaviour | |
link.sender | A person looked up a sender’s website | Lifelike behaviour | |
inspect.scored | An email your app sent was inspected and scored | ||
inspect.links | The links of an email your app sent were checked | ||
world.mail | Mail arrived on its own from the World | ||
job.scheduled, job.done, job.skipped, job.failed | Something was scheduled, ran, was skipped or failed | ||
writer.fallback | A reply was written from a template because the AI was unavailable |
“Needs” is the plan feature without which the event never happens. The remaining kinds (settings changes, sign-ins, deletions, the deliverability checker) are listed under waits in the settings reference.
Wait until a conversation goes quiet
Section titled “Wait until a conversation goes quiet”GET /api/wait/thread
Section titled “GET /api/wait/thread”Returns a whole thread once no new message has joined it for a while: the moment to check what your AI agent and the people it wrote to have said.
| Parameter | Default | Meaning |
|---|---|---|
message_id | Any message of the thread. message_id or thread is required. | |
thread | The thread’s first Message-ID. | |
quiet | 10s | How long no new message may join (real time, not simulated). |
fast | true has the people in the thread act now on what they have queued, so the conversation plays out at once. | |
timeout | 60s | As above. |
curl -s -G https://c1.simmail.dev/api/wait/thread \ -H "Authorization: Bearer smk_your_key" \ --data-urlencode "quiet=10s" \ --data-urlencode "fast=true"It answers {"thread": "…", "messages": [ … oldest first … ], "count": 6, "quiet_ms": 10012, "waited_ms": 41870}, or 408 (wait_timeout) with the messages so far if the thread was still busy at the timeout.
const sent = await mail.send({ from: "[email protected]", to: ["[email protected]"], subject: "Offer", text: "Would you take 165k?" });const talk = await mail.waitForThread({ messageId: sent.message_id, quiet: "10s", fast: true });console.log(talk.messages.length, talk.latest.text);talk = mail.wait_for_thread(sent["message_id"], quiet=10, fast=True)print(len(talk.messages), talk.latest.text)A message you got from a wait also has waitUntilQuiet() (wait_until_quiet() in Python).
Extract codes and links
Section titled “Extract codes and links”POST /api/extract
Section titled “POST /api/extract”Runs the same extraction on any text or HTML you send.
curl -s -X POST https://c1.simmail.dev/api/extract \ -H "Authorization: Bearer smk_your_key" \ -H "Content-Type: application/json" \ -d '{"text": "Your code is 482913. Reset your password: https://app.yourcompany.test/reset?token=xyz"}'{ "codes": ["482913"], "links": ["https://app.yourcompany.test/reset?token=xyz"], "magic_links": ["https://app.yourcompany.test/reset?token=xyz"]}How codes and links are found
Section titled “How codes and links are found”codes: 4 to 8 digits, or 6 to 8 letters and digits with at least one digit, shortly after a word such as code, OTP, PIN, passcode, verification, verify, one-time or security. A line holding only 4 to 8 digits also counts. When the email has only HTML, its text is used.links: every link in the text and HTML.magic_links: links whose address contains verify, verification, confirm, magic, sign-in, signin, login, log-in, reset, activate, auth ortoken=. Unsubscribe links are never magic links.
All three are always lists, empty when nothing is found.