Inbound rules
Durable rules that act on mail as it arrives, without your code running: what a rule matches, the four actions, the order they run in, what keeps generated mail from looping, and the history of every run.
On this page
What a rule is
A rule belongs to one inbox and says: when a message like this arrives, do that. It is stored in the API and runs there, so it acts on mail while your agent is asleep, restarting or not yet written. A rule can label a thread, answer the sender from a template, forward the message, or move it to the trash.
An inbox holds at most 25 rules, and a rule at most 5 actions. Rules are for the fixed part of handling mail. Anything that needs judgment belongs in a handler: The agent runtime.
Creating a rule
POST /v1/inboxes/{inboxId}/rules takes a name, what to match under when, and the actions under then. A new rule is enabled and applies to the next message that arrives.
curl -s -X POST "https://api.doorman.fyi/v1/inboxes/inb_01jc4q7w9k2m5n8p3r6t1v4x7z/rules" \
-H "authorization: Bearer $DOORMAN_API_KEY" \
-H "content-type: application/json" \
-d '{
"name": "Invoice triage",
"when": {
"category": "personal",
"subjectContains": "invoice"
},
"then": [
{
"type": "label",
"label": "billing"
}
]
}'const rule = await client.inboxes.rules.create("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", {
name: "Invoice triage",
when: { category: "personal", subjectContains: "invoice" },
then: [{ type: "label", label: "billing" }],
});rule = client.inboxes.rules.create("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", {
"name": "Invoice triage",
"when": {"category": "personal", "subjectContains": "invoice"},
"then": [{"type": "label", "label": "billing"}],
})doorman inboxes rules create inb_01jc4q7w9k2m5n8p3r6t1v4x7z --name "Invoice triage" \
--when '{"category":"personal","subjectContains":"invoice"}' \
--then '[{"type":"label","label":"billing"}]'{
"id": "rul_01jc5f1a2b3c4d5e6f7g8h9j0k",
"inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
"name": "Invoice triage",
"enabled": true,
"when": {
"category": "personal",
"subjectContains": "invoice"
},
"then": [
{
"type": "label",
"label": "billing"
}
],
"createdAt": "2026-11-05T10:05:00.000Z",
"updatedAt": "2026-11-05T10:05:00.000Z"
}What a rule matches
Every condition given under when has to hold for the rule to match. A condition that is left out is not checked.
Conditions: RuleWhen
All supplied conditions must match. At least one condition is required.
category"personal" | "automated" | "marketing" | "bounce" | "spam" | "malicious"optionalsenderstring (email)optionalExact normalized From address. A match is not proof of sender identity.
subjectContainsstringoptionalCase-insensitive subject substring, not a regular expression.
minRiskLevel"low" | "medium" | "high" | "critical"optionalThe message's risk level is this or higher. A message that was not assessed never matches.
senderStanding"trusted" | "known" | "new" | "blocked"optionalThe sender's standing when the message arrived. A message that was not assessed never matches.
- A sender match compares the
Fromaddress. It is not proof of who sent the message: mail can claim any sender. subjectContainsis a plain substring of at most 200 characters, matched without regard to case. It is not a pattern.- The risk and standing conditions read the risk assessment the message was given. A message that was not assessed never matches them.
What a rule does
Actions: RuleAction
One of:
Alternative 1
type"label"requiredlabelThreadLabelrequired
Alternative 2
type"auto_reply"requiredtextstringrequiredPlain text, with optional {{sender}}, {{subject}} and {{inbox}} substitutions. No code, HTML or remote templates.
Alternative 3
type"forward"requiredtostring (email)required
Alternative 4
type"trash"required
label- Adds one label to the message's thread.
auto_reply- Answers the sender with a plain-text template of at most 10,000 characters.
{{sender}},{{subject}}and{{inbox}}are replaced, once. A template runs no code and loads nothing. forward- Sends the message's sender, subject and plain text to one address, without its attachments, as a new thread.
trash- Moves the thread to the trash.
Order, and mail that does not loop
- Rules are tried oldest first. Every enabled rule that matches runs, and its actions run in the order written. A rule holds at most one action that sends mail.
- For one inbound message at most 1 action that sends mail is carried out, across all the rules that matched: the first one in order. Where a guard refuses it, no later one takes its place.
- An auto-reply or a forward is sent only for mail that is personal, safe to answer automatically and not rated suspicious, and never to the inbox itself. An auto-reply goes to the message's
Reply-To, or to its sender. - Generated mail counts against the inbox's sending limits like any other send.
- What a rule will do to a message is fixed when the message arrives. Editing or deleting the rule afterwards cancels what had not started, and cannot recall mail that already left.
The history of a rule
GET /v1/inboxes/{inboxId}/rules/{ruleId}/runs lists what the rule did, newest first: one run for each message it matched, with the event it ran for, how many actions were carried out, and a reason that holds no mail content. The history stays readable after the rule is deleted.
pending- The rule matched and its actions are waiting to run.
running- The actions are being carried out now.
completed- At least one action was carried out.
skippedActionscounts the ones that were not, andlastErrorholds the reason for the last of them. failed- An action failed, and the ones after it did not run. The actions before it stay done.
lastErroris the send's error code, orexecution_failed. skipped- No action was carried out, and
lastErrorsays why. uncertain- A send may or may not have left: the run was interrupted, or the provider's answer was lost. It is not sent again, because the provider may already have accepted it.
Why an action was skipped
lastError | An action was skipped because |
|---|---|
outbound_action_limit | Another rule's action was the one chosen to send mail for this message. |
auto_reply_blocked | The message is not clean personal mail, so nothing is sent for it. |
self_or_invalid_recipient | The mail would have gone to the inbox itself, or to an address that is not valid. |
message_unavailable | The message is no longer there to answer or forward. |
rule_or_inbox_unavailable | The rule was changed, disabled or deleted, or the inbox or the account is no longer active. |
thread_unchanged | The thread already had the label, or was already in the trash. |
for await (const run of client.inboxes.rules.iterateRuns("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", "rul_01jc5f1a2b3c4d5e6f7g8h9j0k")) {
console.log(run.eventId, run.status, run.completedActions, run.lastError);
}for run in client.inboxes.rules.iterate_runs("inb_01jc4q7w9k2m5n8p3r6t1v4x7z", "rul_01jc5f1a2b3c4d5e6f7g8h9j0k"):
print(run["eventId"], run["status"], run["completedActions"], run["lastError"])Who may manage rules
Rules are managed with an account key or a console session. An inbox key gets 403 forbidden. An app a person installed needs rules:manage, mail:read, mail:write, mail:send together, because a rule reads mail, changes threads and sends. A rule an app made stops matching when the app's installation ends. See Permissions and account boundaries.

