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.
GET /v3/rulesReturns a list of all rules for your application.
POST /v3/rulesCreates a rule for your application. A rule defines a trigger (inbound or outbound), conditions against sender or recipient fields, and actions to apply when the conditions match. Inbound rules run on...
GET /v3/rules/{rule_id}Returns the specified rule.
PUT /v3/rules/{rule_id}Updates the specified rule. All fields are optional — only provided fields are updated. The same validation rules apply as on create.
DELETE /v3/rules/{rule_id}Deletes the specified rule. This action is irreversible. Policies that reference the rule no longer apply it during inbound processing, and outbound sends no longer evaluate it after deletion.
GET /v3/grants/{grant_id}/rule-evaluationsReturns a paginated list of rule evaluation records for the specified grant. Each record captures which rules were evaluated against an inbound message, SMTP envelope, or outbound send, the normalized...