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
  1. What a rule is
  2. Creating a rule
  3. What a rule matches
  4. What a rule does
  5. Order, and mail that does not loop
  6. The history of a rule
  7. Who may manage rules
  8. The operations

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"
      }
    ]
  }'

201 Created

{
  "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"optional

  • senderstring (email)optional

    Exact normalized From address. A match is not proof of sender identity.

  • subjectContainsstringoptional

    Case-insensitive subject substring, not a regular expression.

  • minRiskLevel"low" | "medium" | "high" | "critical"optional

    The message's risk level is this or higher. A message that was not assessed never matches.

  • senderStanding"trusted" | "known" | "new" | "blocked"optional

    The sender's standing when the message arrived. A message that was not assessed never matches.

  • A sender match compares the From address. It is not proof of who sent the message: mail can claim any sender.
  • subjectContains is 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

Alternative 2

  • type"auto_reply"required

  • textstringrequired

    Plain text, with optional {{sender}}, {{subject}} and {{inbox}} substitutions. No code, HTML or remote templates.

Alternative 3

  • type"forward"required

  • tostring (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. skippedActions counts the ones that were not, and lastError holds 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. lastError is the send's error code, or execution_failed.
skipped
No action was carried out, and lastError says 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

lastErrorAn action was skipped because
outbound_action_limitAnother rule's action was the one chosen to send mail for this message.
auto_reply_blockedThe message is not clean personal mail, so nothing is sent for it.
self_or_invalid_recipientThe mail would have gone to the inbox itself, or to an address that is not valid.
message_unavailableThe message is no longer there to answer or forward.
rule_or_inbox_unavailableThe rule was changed, disabled or deleted, or the inbox or the account is no longer active.
thread_unchangedThe 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);
}

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.

The operations

Up Down to move, Enter to open, Esc to close