# Rules

Source: https://developer.nylas.com/docs/reference/api/rules/

The Rules endpoints let you define automated filtering and routing logic for Nylas Agent Accounts. Each rule specifies a `trigger` (`inbound` or `outbound`), matching conditions, and actions to perform when those conditions are met.

**Inbound rules** run when mail arrives. Conditions match the sender — `from.address`, `from.domain`, or `from.tld`. Actions include blocking the message at the SMTP level, marking as spam, assigning to a folder, marking as read or starred, archiving, and trashing.

**Outbound rules** run before a send is submitted to the email provider. Conditions can match sender data (`from.address`, `from.domain`, `from.tld`), recipient data (`recipient.address`, `recipient.domain`, `recipient.tld`), or the send type via `outbound.type` (`compose` for new messages, `reply` for replies). A `block` action on an outbound rule rejects the send with HTTP 403 before it reaches the provider, so no message is delivered and no sent copy is stored. Non-blocking actions (`mark_as_spam`, `archive`, `mark_as_read`, `mark_as_starred`, `assign_to_folder`, `trash`) apply to the stored sent copy. `recipient.*` fields match against **any** recipient — including To, CC, BCC, and SMTP envelope recipients.

Inbound and outbound rules are isolated. Inbound rules never run during sends, and outbound rules never run on message receipt, so stored sent copies aren't re-evaluated against inbound rules.

Rules are evaluated in priority order (lower numbers first). Inbound rules are applied through the recipient grant's policy. Outbound rules are currently evaluated from the sending application's enabled outbound rules. The `block` action is terminal and cannot be combined with other actions.

Rules support the `in_list` condition operator, which checks field values against Lists (managed via the Lists API) for dynamic, maintainable allow and block lists. `in_list` works for `from.*` and `recipient.*` fields but not for `outbound.type`, which accepts only `is` and `is_not`.

Rule executions are audited per grant. List evaluation records with `GET /v3/grants/{grant_id}/rule-evaluations` to see which inbound or outbound rules ran, what normalized input was considered, and which actions were applied.


## Endpoints

- **GET** `/v3/rules` - [List rules](https://developer.nylas.com/docs/reference/api/rules/list-rules/)
- **POST** `/v3/rules` - [Create a rule](https://developer.nylas.com/docs/reference/api/rules/create-rule/)
- **GET** `/v3/rules/{rule_id}` - [Get a rule](https://developer.nylas.com/docs/reference/api/rules/get-rule/)
- **PUT** `/v3/rules/{rule_id}` - [Update a rule](https://developer.nylas.com/docs/reference/api/rules/update-rule/)
- **DELETE** `/v3/rules/{rule_id}` - [Delete a rule](https://developer.nylas.com/docs/reference/api/rules/delete-rule/)
- **GET** `/v3/grants/{grant_id}/rule-evaluations` - [List rule evaluations](https://developer.nylas.com/docs/reference/api/rules/list-rule-evaluations/)
