MOLTED EMAIL

Mailbox Rules

Label or archive new inbound conversations automatically, based on sender or subject.

Mailbox rules automatically label or archive new inbound conversations. Each rule defines a condition (what to match) and an action (what to do). Rules run in priority order and can optionally stop processing further rules when matched.

Rules run once per conversation: on the inbound message that starts a new thread. A reply that joins an existing thread is not evaluated again. Every enabled rule of the thread's mailbox whose condition matches applies its action, in position order, until one with stopProcessing: true matches.

Rules are managed with your Bearer token, through the mailbox service (/v1/agent/rules on https://mailbox.molted.email, which fills in your tenantId from the key; on api.molted.email every call carries it), or the CLI (molted rules). The MCP server has no rule tools.

Create a rule

POST https://mailbox.molted.email/v1/agent/rules
curl
curl -X POST "https://mailbox.molted.email/v1/agent/rules" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "mailboxId": "MAILBOX_UUID",
    "name": "Archive newsletters",
    "conditionType": "sender_domain",
    "conditionOperator": "ends_with",
    "conditionValue": "newsletter.example.com",
    "actionType": "auto_archive",
    "enabled": true,
    "stopProcessing": false
  }'
Response
{
  "id": "rule_uuid",
  "mailboxId": "MAILBOX_UUID",
  "name": "Archive newsletters",
  "conditionType": "sender_domain",
  "conditionOperator": "ends_with",
  "conditionValue": "newsletter.example.com",
  "actionType": "auto_archive",
  "actionValue": null,
  "enabled": true,
  "position": 0,
  "stopProcessing": false
}

Condition types

TypeMatches against
sender_domainThe domain portion of the sender's email address.
sender_emailThe full sender email address.
subjectThe message subject line.

Condition operators

Every operator ignores case.

OperatorDescription
equalsThe whole value matches exactly.
containsSubstring match.
matches_patternA SQL LIKE-style pattern over the whole value: % matches any run of characters, _ any one character (for example %invoice% or support@%.example.com). It is not a glob: * and ? are literal.
ends_withSuffix match.

Actions

ActionactionValueDescription
apply_labelLabel IDApply a label of the same mailbox to the new thread, recorded as applied by the rule (appliedBy: { "type": "rule" }).
move_to_folderLabel IDThe old name of apply_label; still works.
auto_archiveNot requiredArchive the new thread immediately (it moves to the archived view).

Request fields

FieldTypeRequiredDescription
mailboxIdstringYesUUID of the mailbox to attach the rule to.
namestringYesHuman-readable label for the rule.
conditionTypestringYesWhat to match against.
conditionOperatorstringYesHow to compare.
conditionValuestringYesThe value to compare against. For matches_pattern, at most 200 characters and 10 % wildcards (a longer pattern is a 400). Only the first 2,000 characters of the sender or subject are compared.
actionTypestringYesWhat to do when the condition matches.
actionValuestringFor apply_label / move_to_folderThe label ID. Missing is 400; a label that isn't in the rule's mailbox is 404.
enabledbooleanNoWhether the rule is active. Defaults to true.
positionintegerNoSort order. Lower values run first; rules with the same position run oldest first. Defaults to 0.
stopProcessingbooleanNoStop evaluating further rules when this one matches. Defaults to true (on the API and in molted rules create); pass false / --no-stop-processing to let later rules run too.

Rule names are unique within a mailbox (409 otherwise).

CLI
molted rules create --mailbox MAILBOX_UUID --name "Archive newsletters" \
  --condition-type sender_domain --condition-operator ends_with \
  --condition-value newsletter.example.com --action-type auto_archive \
  --no-stop-processing

List rules

mailboxId is required (400 without it). Rules come back in evaluation order.

GET https://mailbox.molted.email/v1/agent/rules?mailboxId=MAILBOX_UUID
curl
curl "https://mailbox.molted.email/v1/agent/rules?mailboxId=MAILBOX_UUID" \
  -H "Authorization: Bearer YOUR_API_KEY"
CLI
molted rules list --mailbox MAILBOX_UUID

Get a rule

GET https://mailbox.molted.email/v1/agent/rules/:id
CLI
molted rules get RULE_UUID

Update a rule

PATCH https://mailbox.molted.email/v1/agent/rules/:id
curl
curl -X PATCH "https://mailbox.molted.email/v1/agent/rules/RULE_UUID" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled": false}'

All fields from the create request except mailboxId are optional for updates. Enabling a rule whose label is gone, or that has no actionValue for its label action, is 400.

CLI
molted rules update RULE_UUID --no-enabled

Delete a rule

DELETE https://mailbox.molted.email/v1/agent/rules/:id
curl
curl -X DELETE "https://mailbox.molted.email/v1/agent/rules/RULE_UUID" \
  -H "Authorization: Bearer YOUR_API_KEY"
CLI
molted rules delete RULE_UUID

Reorder rules

Rules are evaluated in ascending position order. Use the reorder endpoint to set the evaluation order explicitly.

POST https://mailbox.molted.email/v1/agent/rules/reorder
curl
curl -X POST "https://mailbox.molted.email/v1/agent/rules/reorder" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "mailboxId": "MAILBOX_UUID",
    "ruleIds": ["rule-uuid-1", "rule-uuid-2", "rule-uuid-3"]
  }'

Rules are assigned positions in the order of the ruleIds array (first element = position 0). ruleIds must list every rule of the mailbox exactly once (400 otherwise). The response is the mailbox's rules in their new order.

CLI
molted rules reorder --mailbox MAILBOX_UUID --rule-ids rule-uuid-1,rule-uuid-2,rule-uuid-3

Stop processing

When stopProcessing: true is set on a rule, evaluation halts after the rule matches. This is useful for high-priority rules that should take exclusive action.

Label deletion

Deleting a label automatically disables (does not delete) any rule whose apply_label (or move_to_folder) action targets it. Update the rule to point at a different label, or delete it, once you no longer need it. A matching inbound message is never dropped because of a rule pointing at a deleted label: it still lands in the inbox even if the rule's action can't be applied.

A label applied by a rule is business metadata: it never changes how the message is routed, held or quarantined. A rule labels the thread even when its first message is quarantined or the thread goes to a review queue; the thread.labeled event only fires for a thread your agent can see.

A rule read (list, get, create, update) carries invalidLabel: true and invalidLabelReason when its label can't be applied: label_missing (deleted) or label_in_other_mailbox (a rule made before a rule had to name a label of its own mailbox). Such a rule matches but applies nothing; point it at a label of its own mailbox.

Authorization

Creating, updating, deleting and reordering rules need the key's manage scope and, for a mailbox-scoped key, manage on the mailbox. Reads need read. See Authentication for key scoping details.

  • Mailboxes: create and manage mailboxes (a clone copies its rules)
  • Labels: the labels a rule applies
  • Inbound: how inbound messages are classified and routed