bulk_by_query
Apply one action—archive, delete, mark read/unread, or move—to every matching email in a single call, with a dry-run preview to prevent accidental mass changes.
Instructions
Find every message matching a query and apply one action to all of them in a single call — the message ids never enter the conversation, so this is by far the cheapest way to triage in bulk.
action: one of archive, delete, mark_read, mark_unread, move
(move requires destination_folder, which may be a folder display name).
folder / filter_query / search: same matching semantics as list_messages
(fetches all matches up to max_results).
received_before / received_after: ISO dates (e.g. "2026-01-01"); applied
client-side AFTER matching, so they compose with search — which Graph
itself won't combine with a date $filter. Use these for "old "
sweeps, e.g. search="delivery" + received_before to clear old shipping mail.
only_newsletters: keep only bulk/newsletter mail (messages with a
List-Unsubscribe header) among the matches, e.g. archive all newsletters
older than a week. Costs an extra batched header pass over the matches.
Note this is a bulk-sender signal, not a junk one — plenty of wanted
mail (order updates, voucher codes, statements) carries the header too.
senders_only: keep only matches from these sending addresses (exact,
case-insensitive). Graph rejects a sender $filter combined with
$orderby, so this is applied client-side — it is the supported way to
act per sender. Pair it with sender_summary to pick the addresses.
on_protected: what to do about matches from protected senders (see
protected_senders): "exclude" (default, skip them and report),
"error" (do nothing at all and report), "include" (ignore the list).
dry_run: TRUE by default — returns how many messages would be affected plus a
small sample of subjects/senders, and does nothing. Review it, then call
again with dry_run=False to actually run the action. This guards against
a bad filter nuking the wrong mail.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | ||
| folder | No | inbox | |
| search | No | ||
| dry_run | No | ||
| max_results | No | ||
| filter_query | No | ||
| on_protected | No | exclude | |
| senders_only | No | ||
| received_after | No | ||
| received_before | No | ||
| only_newsletters | No | ||
| destination_folder | No |