# Mail Rules Editor

> Rules for incoming mail: if all (or any) of the conditions match (from, to, subject or text contains, doesn't contain, is, starts or ends with), then run the actions (move to a folder, archive, mark as read, star, forward, hand to an agent,

Component · Forms · Pro kit · [Live page](https://ui.twentyfirst.media/pro/components/MailRulesEditor/)

Rules for incoming mail: if all (or any) of the conditions match (from, to, subject or text contains, doesn't contain, is, starts or ends with), then run the actions (move to a folder, archive, mark as read, star, forward, hand to an agent, delete). Each rule has a name and can be switched off. The value is a list of `MailRule`s; `onSave` adds a save button.

## Example

```tsx
import { MailRulesEditor } from "@twentyfirstmedia/pro";

export default function Preview() {
  return (
    <MailRulesEditor
      folders={[
        { value: "receipts", label: "Receipts" },
        { value: "clients", label: "Clients" },
        { value: "archive", label: "Archive" },
      ]}
      agents={[
        { value: "bookkeeper", label: "Bookkeeper" },
        { value: "support", label: "Support agent" },
      ]}
      defaultValue={[
        {
          id: "r1",
          name: "Invoices to Receipts",
          enabled: true,
          match: "any",
          conditions: [
            { field: "subject", op: "contains", value: "invoice" },
            { field: "from", op: "endsWith", value: "@billing.example.com" },
          ],
          actions: [
            { type: "move", value: "receipts" },
            { type: "handoff", value: "bookkeeper" },
          ],
        },
        {
          id: "r2",
          name: "Quiet newsletters",
          enabled: false,
          match: "all",
          conditions: [{ field: "body", op: "contains", value: "unsubscribe" }],
          actions: [{ type: "markRead" }, { type: "archive" }],
        },
      ]}
      onSave={() => {}}
    />
  );
}
```

## Props

### MailRulesEditor

| Prop | Type | Notes |
| --- | --- | --- |
| `value?` | `MailRule[]` |  |
| `defaultValue?` | `MailRule[]` |  |
| `onChange?` | `(rules: MailRule[]) => void` |  |
| `folders?` | `Option[]` | Folders for "Move to". |
| `agents?` | `Option[]` | Agents for "Hand to agent" (the action shows only with agents). |
| `onSave?` | `(rules: MailRule[]) => void` | Shows "Save rules". |
| `saving?` | `boolean` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
