ドキュメント本文へスキップ
CLI

openemail rules

この名前空間のすべてのコマンドと、その引数、フラグ、例。

コマンド

Conditions and actions evaluated on arriving mail, with dry runs and an audit trail.

ここのすべてのコマンドは、--json、--profile、--dry-run などのグローバルフラグも受け付けます。 グローバルフラグを見る

openemail rules list

List mail rules in evaluation order

スコープrules:readサインインが必要エイリアスls

使い方

openemail rules list [flags]

Returns one page of the mailbox's rules in the order they run on arriving mail: ascending position, then createdAt, then id. This is deliberately not newest first. With stopProcessing in play, the same rules in a different order file mail differently, so the order you read is the order that matters.

Paging is keyset on that same (position, createdAt, id) tuple, and the cursor is opaque: it holds where the last rule on the page sat in that order. --enabled narrows to enabled or disabled rules, and the SDK sends it as the literal word true or false.

Add --all to walk every page: a table on a terminal, one JSON object per line when piped or with --ndjson, and one { items, hasMore, nextCursor } document with --json. --max <n> stops after that many items.

フラグ

--enabled

Restricts the page to enabled (true) or disabled (false) rules. Omit it for both.

--limit <n>

Rows per page, a whole number from 1 to 100. The server defaults to 25.

既定値25
--cursor <value>

The nextCursor from the previous page. Never build one yourself.

--all

Fetch every page and stream the items as they arrive.

--max <n>

Stop after this many items. Implies --all.

--ndjson

Print every item as one JSON object per line. Implies --all

例

openemail rules list
With optional flags
openemail rules list --enabled --limit 100
Walk every page and stop after 100 items
openemail rules list --all --max 100
One JSON object per line when piped
openemail rules list --all > rules.ndjson

ほかの提供先

API
GET /rules
SDK
rules.list()

openemail rules get

Read one mail rule

スコープrules:readサインインが必要エイリアスshowview

使い方

openemail rules get <id> [flags]

Fetches a single rule by its rul_ id. Rules have no slug and the name is editable, so store the id if your code needs to find the rule again.

The stored conditions are normalised, so negate is always present and false unless you set it. lastMatchedAt and matchCount move each time the rule fires on an arriving message, which makes them the quickest way to see whether a rule is doing anything without reading listRuns.

引数

<id>必須

The rule's rul_ id.

例

openemail rules get rul_4f1c9a2b7d3e8f6a0b5c1d2e
Print the raw JSON
openemail rules get rul_4f1c9a2b7d3e8f6a0b5c1d2e --json

ほかの提供先

API
GET /rules/{id}
SDK
rules.get()

openemail rules create

Create a mail rule at the end of the order

スコープrules:writeサインインが必要エイリアスnewadd

使い方

openemail rules create --name <value> --conditions <json|@file|-> --actions <json|@file|-> [flags]
openemail rules create --data <json|@file|-> [flags]

Creates a rule that runs on mail arriving in the mailbox, with no API call involved once it exists. It is appended after every existing rule and is enabled unless you pass enabled: false. There is no position on create: move the rule afterwards with reorder, the only call that guarantees an exact sequence. Creating it disabled and calling test first is the safe order.

Conditions are a flat list. match: 'all' is AND, match: 'any' is OR, and negate: true inverts a single condition, so (A and B) or C takes two rules. value is always a string. has_attachment and spam take only equals with 'true' or 'false'. attachment_size, message_size, hour and weekday take a number with gt, lt or equals, and gt or lt on any other field is refused. Text comparisons ignore case, and matches is a whole value glob over * and ? that needs at least two letters or digits. A header condition must name the header it reads in header.

Actions apply in order. label and remove_label take a label id, forward takes an email address and reply takes a template id or slug. A forward is only delivered once the destination has confirmed it accepts mail forwarded from your domain, and a reply goes to each sender at most once per 24 hours and never to bounces, auto-responders or mailing lists. A rule with reject must also test envelope_from, otherwise it is a 422 reject_needs_envelope, because refusing mail on the strength of a From header bounces the mailing list rather than the author.

フラグ

--name <value>

Display name, 1 to 100 characters after trimming and unique per mailbox. Required, here or in --data.

--description <value>

Free text note, at most 500 characters.

--enabled

Whether the rule runs on arriving mail. Defaults to true.

既定値true
--match <value>

Whether every condition or any single one must hold. Defaults to all.

既定値"all"
--conditions <json|@file|->

1 to 20 conditions, each { field, op, value } with optional header (at most 128 characters) and negate. value is at most 512 characters. JSON shaped as Array<RuleConditionInput>, inline or from a file with @path. Required, here or in --data.

--actions <json|@file|->

1 to 10 actions, each { type, value }, with value at most 320 characters. JSON shaped as Array<RuleAction>, inline or from a file with @path. Required, here or in --data.

--stop-processing

When true, no later rule runs on a message this rule matched. Defaults to false.

既定値false
--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

例

The required values only
openemail rules create --name 'Receipts to their own label' --conditions @conditions.json --actions @actions.json
With optional flags
openemail rules create --name 'Receipts to their own label' --conditions @conditions.json --actions @actions.json --no-enabled --stop-processing
Read the whole body from a JSON file
openemail rules create --data @rule.json

ほかの提供先

API
POST /rules
SDK
rules.create()

openemail rules update

Change a rule, replacing conditions or actions whole

スコープrules:writeサインインが必要エイリアスedit

使い方

openemail rules update <id> [flags]

Merges the patch onto the stored rule and validates the whole result, so an omitted field keeps its stored value instead of collecting a default. A patch that only renames a rule cannot switch a disabled one back on, and a patch that adds a reject action is checked against the conditions already stored.

conditions and actions replace the entire array. There is no way to add or remove a single element: read the rule, change the array, and send all of it. match and --stop-processing read across the whole set, which is why element level edits are not offered.

position moves this one rule without renumbering the others. Positions are not unique and ties break by createdAt then id, so landing on an occupied position puts the older rule first. Use reorder when the exact sequence matters. Setting enabled: false is the reversible alternative to delete, and a disabled rule keeps its place in the order.

引数

<id>必須

The rule's rul_ id.

フラグ

--name <value>

Replacement name, 1 to 100 characters and unique per mailbox.

--description <value>

Replacement note of at most 500 characters, or null to clear it.

--enabled

Turns the rule on or off without moving it.

既定値true
--match <value>

Whether every condition or any single one must hold.

既定値"all"
--conditions <json|@file|->

Complete replacement list of 1 to 20 conditions. JSON shaped as Array<RuleConditionInput>, inline or from a file with @path.

--actions <json|@file|->

Complete replacement list of 1 to 10 actions. JSON shaped as Array<RuleAction>, inline or from a file with @path.

--stop-processing

When true, no later rule runs on a message this rule matched.

既定値false
--position <n>

New position, a whole number from 0 to 1,000,000. Other rules keep theirs.

--data <json|@file|->

The whole patch as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

例

With optional flags
openemail rules update rul_4f1c9a2b7d3e8f6a0b5c1d2e --enabled
Print the raw JSON
openemail rules update rul_4f1c9a2b7d3e8f6a0b5c1d2e --enabled --json

ほかの提供先

API
PATCH /rules/{id}
SDK
rules.update()

openemail rules delete

Delete a mail rule

スコープrules:writeサインインが必要
確認を求めます
エイリアスrmdelremove

使い方

openemail rules delete <id> [flags]

Permanently removes a rule. There is no undo, and mail it already filed stays where it put it. If you might want the rule back, update(id, { enabled: false }) switches it off and keeps its place in the order.

The run history survives. listRuns({ ruleId }) still returns what the rule did, under the name it had at the time. The other rules are not renumbered, so a gap in position is normal afterwards.

引数

<id>必須

The rule's rul_ id.

例

openemail rules delete rul_4f1c9a2b7d3e8f6a0b5c1d2e
Skip the confirmation, for scripts
openemail rules delete rul_4f1c9a2b7d3e8f6a0b5c1d2e --yes

ほかの提供先

API
DELETE /rules/{id}
SDK
rules.delete()

openemail rules reorder

Set the evaluation order of every rule

スコープrules:writeサインインが必要

使い方

openemail rules reorder <rule-ids...> [flags]

Replaces the whole order in one transaction. ruleIds must name every rule on the mailbox exactly once, and each rule's position becomes its index in the array, starting at 0. Either the whole order lands or nothing moves.

A list that leaves a rule out or names one twice is a 422 incomplete_order, because an omitted rule would have to go somewhere and there is no right answer for where. Build the list from listAll() without the enabled filter so disabled rules are included. The new order applies to the next message that arrives, and mail already filed is not revisited.

引数

<rule-ids...>必須1つ以上

Every rule id on the mailbox in the order they should run, 1 to 100 entries.

例

openemail rules reorder rul_4f1c9a2b7d3e8f6a0b5c1d2e
Print the raw JSON
openemail rules reorder rul_4f1c9a2b7d3e8f6a0b5c1d2e --json

ほかの提供先

API
POST /rules/reorder
SDK
rules.reorder()

openemail rules test

Dry run a rule against mail already in the mailbox

スコープrules:readサインインが必要

使い方

openemail rules test <id> [flags]

Evaluates one rule against stored mail with the same matcher delivery uses and reports what it would have caught and what it would do. It changes nothing, sends nothing and files nothing, which is why it needs only rules:read. It works on a disabled rule, so the intended sequence is create with enabled: false, test, then enable.

By default it reads up to 50 inbox threads from the last 30 days. For each thread it tests the newest message the mailbox received rather than sent, and threads that fail to load or hold only your own messages are skipped, so scanned can come in below limit. Pass --thread-ids to test specific threads from any folder instead, and days and limit are then ignored. A message an existing rule already moved out of the inbox is not in the default sample, and listRuns is the record of what really happened.

Read warnings before matched. field_unevaluable means a condition reads something stored mail no longer carries (envelope_from, header, list_id, delivered_to or message_size), so it never held here, and under negate it holds on everything. field_approximate flags attachment, hour and weekday conditions answered from stored data that can differ from delivery. body_encrypted means a body condition met mail whose body is sealed. forward_loop means a forward target leads back to this mailbox, and forward_unverified means the target is not hosted here, so the forwarded copy is rebuilt and loses its original DKIM signature.

引数

<id>必須

The rule's rul_ id. Disabled rules can be tested.

フラグ

--thread-ids <a,b>複数指定可

Up to 50 specific thread ids to test instead of the recent window. Ids that fail to load are skipped.

--days <n>

How far back the default window reaches, 1 to 365. Defaults to 30.

既定値30
--limit <n>

How many recent inbox threads to read, 1 to 200. Defaults to 50.

既定値50
--data <json|@file|->

The whole body as JSON, inline, from a file with @path, or - for standard input. Flags override its keys.

例

The required values only
openemail rules test rul_4f1c9a2b7d3e8f6a0b5c1d2e
With optional flags
openemail rules test rul_4f1c9a2b7d3e8f6a0b5c1d2e --days 30 --limit 100

ほかの提供先

API
POST /rules/{id}/test
SDK
rules.test()

openemail rules list-runs

List what rules actually did to arriving mail

スコープrules:readサインインが必要

使い方

openemail rules list-runs [flags]

Returns one page of the rule audit log, newest first. Each row is one rule matching one arriving message, with the actions that took effect and the ones that were refused.

Each row copies the rule's name at the moment it fired, so renamed and deleted rules still read correctly, and --rule-id works for a rule that no longer exists. --thread-id answers the other common question: why a particular message ended up where it did.

actions lists the action types that were applied, and failures lists refusals as type: reason. A non empty failures means the rule matched but the mailbox declined part of it, for example a reply suppressed because that sender was already answered in the last day, a forward to an address that has not confirmed, or a reject that could not be refused at SMTP and was filed as spam instead.

Add --all to walk every page: a table on a terminal, one JSON object per line when piped or with --ndjson, and one { items, hasMore, nextCursor } document with --json. --max <n> stops after that many items.

フラグ

--rule-id <value>

Only runs of this rule, including a rule that has since been deleted.

--thread-id <value>

Only runs recorded against this thread.

--limit <n>

Rows per page, a whole number from 1 to 100. The server defaults to 25.

既定値25
--cursor <value>

The nextCursor from the previous page. Never build one yourself.

--all

Fetch every page and stream the items as they arrive.

--max <n>

Stop after this many items. Implies --all.

--ndjson

Print every item as one JSON object per line. Implies --all

例

openemail rules list-runs
With optional flags
openemail rules list-runs --rule-id rul_4f1c9a2b7d3e8f6a0b5c1d2e --limit 50
Walk every page and stop after 100 items
openemail rules list-runs --all --max 100
One JSON object per line when piped
openemail rules list-runs --all > rules.ndjson

ほかの提供先

API
GET /rules/runs
SDK
rules.listRuns()