Skip to content

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 forSection
The next email (or the next few)Wait for an email
No email at all, for a whileMake sure no email arrives
A person’s replyWait for a reply
Something a person does: opens a link, junks you, bounces, promisesWait for what a person does
A conversation to go quietWait until a conversation goes quiet

Returns the next email that matches every filter you give.

ParameterDefaultMeaning
toThe 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.
tagEvery test address made with this tag.
fromPart of the sender’s address or name, any case.
subjectWords in the subject, any case.
containsWords in the body (text or HTML), any case.
subject_regexA regular expression the subject must match (RE2 syntax; start it with (?i) to ignore case).
body_regexA regular expression the text or HTML must match.
headerName:value: the header must contain the value, any case. Repeat it for several headers.
has_attachmenttrue for mail with an attached file (inline images do not count), false for mail without.
attachment_namePart of an attachment’s file name, such as .pdf or invoice.
link_domainThe email links to this host or a subdomain of it, such as app.yourcompany.test.
folderINBOXThe folder to watch, such as Junk or Sent.
count1Wait until this many matching emails have arrived (1 to 100).
sinceOnly mail after this: an RFC 3339 time, or the message_id of a message simmail holds. Mail already there counts too.
excludeMessage-IDs to skip, separated by commas.
existingtrue also matches messages already there. Otherwise only mail that arrives after the request starts counts (unless you give since).
timeout30sHow long to wait, as 45s, 2m and so on.
Terminal window
curl -s -G https://c1.simmail.dev/api/wait \
-H "Authorization: Bearer smk_your_key" \
--data-urlencode "[email protected]" \
--data-urlencode "subject=verify" \
--data-urlencode "timeout=20s"
{
"address": "[email protected]",
"folder": "INBOX",
"uid": 1,
"message_id": "<[email protected]>",
"from": "[email protected]",
"from_name": "Acme",
"to": ["[email protected]"],
"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:

JavaScript
const msg = await mail.waitForEmail({ to: "[email protected]", subject: "verify", timeout: "20s" });
console.log(msg.codes[0], msg.magicLinks[0]);
Python
msg = mail.wait_for_email("[email protected]", subject="verify", timeout=20)
print(msg.codes[0], msg.magic_links[0])
Terminal window
# The invoice email, to anyone at the test domain, with a PDF attached,
# a link to the billing site and the campaign header
curl -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"
JavaScript
const invoice = await mail.waitForEmail({
to: "*@yourcompany.test",
subjectRegex: /^invoice #\d+/i,
attachmentName: ".pdf",
linkDomain: "billing.yourcompany.test",
header: { "X-Campaign": "billing" },
});
Python
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"},
)

With count, the wait returns once that many matching emails have arrived, oldest first:

Terminal window
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": [
{ "address": "[email protected]", "subject": "Your weekly digest", "codes": [], "…": "…" },
{ "address": "[email protected]", "subject": "Your weekly digest", "codes": [], "…": "…" }
],
"count": 2,
"waited_ms": 3120,
"matched": ["to", "subject"]
}
JavaScript
const { messages } = await mail.waitForEmail({ to: ["[email protected]", "[email protected]"], subject: "weekly digest", count: 2 });
Python
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.

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": [
{
"message_id": "[email protected]",
"address": "[email protected]",
"from": "[email protected]",
"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).

StatusCodeMeaning
200The email (or, with count, the emails).
400invalid_regexsubject_regex or body_regex is not a valid regular expression; field says which.
400invalid_valueAnother parameter is wrong, such as count outside 1 to 100, a header without a colon, or a since simmail cannot place; field names it.
400bad_requestNeither to nor tag.
408wait_timeoutNothing matched in time; see near_misses.

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:

ParameterDefaultMeaning
toOne or more addresses, or *@domain. to or tag is required.
tagEvery test address made with this tag.
subjectWords in the subject, any case.
for5sHow long nothing may arrive.
Terminal window
curl -s -G https://c1.simmail.dev/api/wait/none \
-H "Authorization: Bearer smk_your_key" \
--data-urlencode "[email protected]" \
--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.

JavaScript
await mail.expectNoEmail({ to: "[email protected]", subject: "welcome", within: "10s" });
Python
mail.expect_no_email("[email protected]", subject="welcome", within=10)

The SDKs raise UnexpectedEmailError (with the email that arrived) instead of returning.

Returns the next email a persona sends.

ParameterDefaultMeaning
fromrequiredThe persona’s address.
in_reply_toOnly 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.
fasttrue has the person write their due reply now, instead of on the simulated clock.
timeout30sAs above.
Terminal window
curl -s -G https://c1.simmail.dev/api/wait/reply \
-H "Authorization: Bearer smk_your_key" \
--data-urlencode "[email protected]" \
--data-urlencode "in_reply_to=<[email protected]>" \
--data-urlencode "fast=true"

The answer has the same fields as above, read from the person’s Sent folder, with by_persona: true.

JavaScript
const reply = await mail.waitForReply({ from: "[email protected]", inReplyTo: "<[email protected]>" }); // fast by default
Python
reply = mail.wait_for_reply("[email protected]", in_reply_to="<[email protected]>") # fast by default

With 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.

StatusMeaning
200The reply.
404Nobody plays that address.
408No reply before the timeout.
409With 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.

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.

Terminal window
curl -s -X POST https://c1.simmail.dev/api/jobs/run-due \
-H "Authorization: Bearer smk_your_key" -H "Content-Type: application/json" \
-d '{"persona": "[email protected]", "kind": "reply"}'
JavaScript
const dana = await mail.personas.byAddress("[email protected]");
await dana.runDue({ kind: JobKind.Reply }); // or: await mail.runDue({ persona: "[email protected]" })
Python
dana = mail.personas.by_address("[email protected]")
dana.run_due(kind=JobKind.REPLY) # or: mail.run_due(persona="[email protected]")

The reply, event and thread waits do this for you with fast=true.

Returns the next event of a kind: a person opening a link, junking your email, bouncing, promising something, replying.

ParameterDefaultMeaning
typerequiredAn event kind or a short name from the table below. Several, separated by commas, or a prefix such as persona.*.
personaOnly events about this person: an id or an address.
message_idOnly events about this message (or a reply to it).
afterOnly events after this event id. By default, only events after the wait starts.
fastWith persona: run what that person has queued now, until the event happens.
timeout30sAs above.
Terminal window
curl -s -G https://c1.simmail.dev/api/wait/event \
-H "Authorization: Bearer smk_your_key" \
--data-urlencode "type=clicked" \
--data-urlencode "[email protected]" \
--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",
"message_id": "<[email protected]>",
"status": 200
}
},
"waited_ms": 640
}
JavaScript
const dana = await mail.personas.byAddress("[email protected]");
const click = await dana.waitFor(EventAlias.Clicked, { fast: true });
Python
dana = mail.personas.by_address("[email protected]")
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).

KindShort namesWhat happenedNeeds
mail.delivereddeliveredMail your app sent was delivered to its recipients
persona.receivedreceivedA person received an email and read it
persona.sentreplied, sentA person sent an email: a reply, a follow-up or a forward
persona.ignoreddeclined, ignoredA person decided not to answer (or their AI is off)
persona.batchedA person will answer several emails together
persona.junkedjunkedA person’s provider filed your email as spam; they never saw itJunk consequences
persona.rescuedrescuedAn email was moved from Junk to a person’s inbox
persona.bouncedbouncedAn address bounced (dead, full, blocked)
persona.promisedpromisedA person promised to do somethingLifelike behaviour
persona.waitingA person is waiting on something you promisedLifelike behaviour
link.openedclicked, opened_linkA person clicked a link in an emailLifelike behaviour
link.skippedA person chose not to open a linkLifelike behaviour
link.failedA person clicked a link and it failedLifelike behaviour
link.senderA person looked up a sender’s websiteLifelike behaviour
inspect.scoredAn email your app sent was inspected and scored
inspect.linksThe links of an email your app sent were checked
world.mailMail arrived on its own from the World
job.scheduled, job.done, job.skipped, job.failedSomething was scheduled, ran, was skipped or failed
writer.fallbackA 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.

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.

ParameterDefaultMeaning
message_idAny message of the thread. message_id or thread is required.
threadThe thread’s first Message-ID.
quiet10sHow long no new message may join (real time, not simulated).
fasttrue has the people in the thread act now on what they have queued, so the conversation plays out at once.
timeout60sAs above.
Terminal window
curl -s -G https://c1.simmail.dev/api/wait/thread \
-H "Authorization: Bearer smk_your_key" \
--data-urlencode "message_id=<[email protected]>" \
--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.

JavaScript
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);
Python
sent = mail.send("[email protected]", ["[email protected]"], "Offer", text="Would you take 165k?")
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).

Runs the same extraction on any text or HTML you send.

Terminal window
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"]
}
  • 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 or token=. Unsubscribe links are never magic links.

All three are always lists, empty when nothing is found.