| 1 | # Email Integration |
| 2 | |
| 3 | Communicate with Agent Zero through email inboxes and send replies back over SMTP. |
| 4 | |
| 5 | ## What It Does |
| 6 | |
| 7 | This plugin polls configured mailboxes, downloads incoming messages and attachments, decides whether a message should continue an existing chat or start a new one, and sends replies back by email. |
| 8 | |
| 9 | It supports both: |
| 10 | |
| 11 | - **IMAP inbox polling** |
| 12 | - **Exchange inbox polling** |
| 13 | - **SMTP replies** |
| 14 | |
| 15 | ## Main Behavior |
| 16 | |
| 17 | - **Mailbox polling** |
| 18 | - Tracks per-handler mailbox state in `usr/email/state.json`. |
| 19 | - Uses UID tracking for IMAP accounts so only new mail is processed after initialization. |
| 20 | - **Attachment handling** |
| 21 | - Downloads attachments into `usr/email/attachments`. |
| 22 | - **Dispatcher workflow** |
| 23 | - Reuses or creates a background `Email Dispatcher` context. |
| 24 | - Uses model prompts to decide whether an email belongs to an existing chat or should open a new one. |
| 25 | - Supports handler-level model presets for new chats, in addition to the dispatcher's utility/chat routing mode. |
| 26 | - **Thread routing** |
| 27 | - Can continue an existing chat by thread ID found in the email subject. |
| 28 | - Falls back to model-based dispatch if no direct thread match is available. |
| 29 | - Email replies inside an existing Agent Zero thread can use `/project`, `/config`, and `/send` control commands. |
| 30 | - **Notifications and persistence** |
| 31 | - Saves chats after routing and emits notifications about new or continued conversations. |
| 32 | |
| 33 | ## Key Files |
| 34 | |
| 35 | - **Core orchestration** |
| 36 | - `helpers/handler.py` manages polling, state persistence, dispatching, and reply flow. |
| 37 | - **Mail helpers** |
| 38 | - `helpers/imap_client.py` handles IMAP and Exchange fetching. |
| 39 | - `helpers/smtp_client.py` handles outbound replies. |
| 40 | - `helpers/dispatcher.py` formats chat summaries and parses dispatcher decisions. |
| 41 | - **API and extensions** |
| 42 | - `api/` and `extensions/` connect the polling loop and UI-facing operations into the main app. |
| 43 | |
| 44 | ## Configuration Scope |
| 45 | |
| 46 | - **Settings section**: `external` |
| 47 | - **Per-project config**: `false` |
| 48 | - **Per-agent config**: `false` |
| 49 | |
| 50 | ## Plugin Metadata |
| 51 | |
| 52 | - **Name**: `_email_integration` |
| 53 | - **Title**: `Email Integration` |
| 54 | - **Description**: Communicate with Agent Zero via email. Supports IMAP/Exchange inbox polling with SMTP replies. |