agenticmail 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,35 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ope Olatunji (https://github.com/ope-olatunji)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ AgenticMail - Email infrastructure for AI agents.
26
+
27
+ Project: https://github.com/agenticmail/agenticmail
28
+ Author: Ope Olatunji
29
+ GitHub: https://github.com/ope-olatunji
30
+
31
+ This software includes components for programmatic email management,
32
+ SMTP/IMAP integration, MCP server tooling, Cloudflare gateway orchestration,
33
+ and OpenClaw plugin infrastructure. All packages within this monorepo
34
+ (@agenticmail/core, @agenticmail/api, @agenticmail/mcp, @agenticmail/openclaw,
35
+ and agenticmail) are covered under this license.
package/README.md ADDED
@@ -0,0 +1,352 @@
1
+ # agenticmail
2
+
3
+ The main package for [AgenticMail](https://github.com/agenticmail/agenticmail) — email infrastructure for AI agents. This is the package you install to get started.
4
+
5
+ It bundles a setup wizard, API server launcher, and a full interactive shell with 36 commands for managing agents, sending and receiving email, configuring gateways, and more. It also re-exports everything from `@agenticmail/core` so you can use it as an SDK.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g agenticmail
11
+ ```
12
+
13
+ **Requirements:** Node.js 20+, Docker (for Stalwart mail server)
14
+
15
+ ---
16
+
17
+ ## Quick Start
18
+
19
+ ```bash
20
+ # 1. Start the Stalwart mail server
21
+ docker compose up -d
22
+
23
+ # 2. Run the setup wizard
24
+ agenticmail setup
25
+
26
+ # 3. Start the API server + interactive shell
27
+ agenticmail start
28
+
29
+ # 4. Check system status
30
+ agenticmail status
31
+ ```
32
+
33
+ ---
34
+
35
+ ## The Setup Wizard
36
+
37
+ Running `agenticmail setup` walks you through everything needed to get email working:
38
+
39
+ 1. **System check** — verifies Docker is running, Stalwart mail server is healthy, and optionally checks for Cloudflared (the Cloudflare tunnel tool). Shows friendly status indicators and auto-installs missing components where possible.
40
+
41
+ 2. **Account creation** — generates a master API key (the admin password for the entire system), creates the `~/.agenticmail` data directory, and initializes the SQLite database with all required tables.
42
+
43
+ 3. **Service startup** — starts Docker if needed, ensures Stalwart is running and healthy.
44
+
45
+ 4. **Email connection** — this is where you choose how your agents connect to the outside world:
46
+
47
+ ### Relay Mode (Recommended for Getting Started)
48
+
49
+ Uses your existing Gmail or Outlook account. You provide your email address and an app password (not your regular password). The wizard:
50
+
51
+ - Lets you pick Gmail, Outlook, or a custom provider
52
+ - Handles Gmail's app password format (strips spaces automatically)
53
+ - Creates your first AI agent
54
+ - Sends a welcome test email
55
+ - Sets up relay polling so incoming mail gets delivered to agent inboxes
56
+ - Retries up to 3 times if authentication fails
57
+
58
+ Agent emails go out as sub-addresses like `yourname+agentname@gmail.com`. Replies come back through the same account.
59
+
60
+ ### Domain Mode (For Professional Use)
61
+
62
+ Uses a custom domain with Cloudflare for DNS, email routing, and tunneling. The wizard:
63
+
64
+ - Takes your Cloudflare API token and account ID
65
+ - Optionally lets you search for and purchase a domain
66
+ - Configures MX records, SPF, DKIM, and DMARC automatically
67
+ - Sets up a Cloudflare Tunnel for inbound email delivery
68
+ - Configures a Cloudflare Email Worker as the catch-all handler
69
+ - Provides manual verification instructions for anything that needs confirmation
70
+
71
+ Agent emails use proper addresses like `secretary@yourdomain.com`.
72
+
73
+ ---
74
+
75
+ ## Starting the Server
76
+
77
+ `agenticmail start` does three things:
78
+
79
+ 1. **Checks prerequisites** — verifies Docker and Stalwart are running. If there's no config file, runs the setup wizard automatically.
80
+
81
+ 2. **Launches the API server** — forks `@agenticmail/api` as a child process, monitors it for crashes (captures the last 50 lines of error output for diagnostics), and waits up to 20 seconds for a health check response.
82
+
83
+ 3. **Drops into the interactive shell** — once the API is healthy, you get an interactive command prompt where you can manage everything.
84
+
85
+ If the server crashes, you get clear error output showing what went wrong.
86
+
87
+ ---
88
+
89
+ ## System Status
90
+
91
+ `agenticmail status` shows a full health report:
92
+
93
+ - **Services** — Docker, Stalwart mail server, Cloudflared (if configured)
94
+ - **Account setup** — whether the config file and database exist
95
+ - **Server health** — API server connectivity and Stalwart reachability
96
+ - **Email gateway** — current mode (relay or domain), provider name, domain name, polling status
97
+
98
+ ---
99
+
100
+ ## The Interactive Shell
101
+
102
+ The shell is the main way to interact with AgenticMail. It provides 36 commands organized by category, with arrow-key navigation, color-coded output, and keyboard shortcuts.
103
+
104
+ ### Getting Around
105
+
106
+ - Type `/` to see the command menu, then use arrow keys to navigate and Enter to select
107
+ - Type any command directly (e.g., `/inbox`)
108
+ - Press **Escape** at any point to cancel and go back
109
+ - Press **Tab** to auto-complete commands
110
+
111
+ ### Email Commands
112
+
113
+ | Command | What It Does |
114
+ |---------|-------------|
115
+ | `/inbox` | Interactive inbox viewer — use arrow keys to select messages, Enter to read, `v` to toggle body previews, left/right arrows for pagination. Unread messages marked with a star. |
116
+ | `/send` | Compose and send an email. Prompts for recipient, subject, and body. Supports file attachments via drag-and-drop or file path. |
117
+ | `/read` | Read a specific email by number. Shows full headers, body, and attachment list. |
118
+ | `/reply` | Reply to an email. Auto-fills the recipient, subject (with Re: prefix), and quoted body. Supports attachments. |
119
+ | `/forward` | Forward an email. Includes original message and attachments. |
120
+ | `/search` | Search emails by keyword. Can search both local inbox and connected relay account (Gmail/Outlook). Offers to import relay results. |
121
+ | `/delete` | Delete an email (shows inbox preview first). |
122
+ | `/save` | Download email attachments to a file. Lets you pick individual attachments or save all. |
123
+ | `/thread` | View an email conversation. Groups messages by subject (strips Re:/Fwd: prefixes) and shows up to 20 messages. |
124
+ | `/unread` | Mark an email as unread. |
125
+ | `/archive` | Move an email to the Archive folder. |
126
+ | `/trash` | Move an email to Trash. |
127
+ | `/sent` | Browse sent emails with pagination. |
128
+ | `/digest` | Quick inbox overview with body previews for each message. |
129
+
130
+ ### Organization Commands
131
+
132
+ | Command | What It Does |
133
+ |---------|-------------|
134
+ | `/folders` | List all folders, create new ones, or browse a specific folder with pagination. |
135
+ | `/contacts` | Manage your address book — list, add, or delete contacts. |
136
+ | `/drafts` | Save, edit, and send draft emails. Also lets you browse the Drafts IMAP folder. |
137
+ | `/signature` | Create and manage email signatures. One can be marked as default (shown with a star). |
138
+ | `/templates` | Create reusable email templates. Use them to quickly send formatted emails. |
139
+ | `/schedule` | Schedule emails for future delivery. Comes with 5 quick presets (30 min, 1 hour, 3 hours, tomorrow 8am, tomorrow 9am) plus custom date/time input with timezone support. |
140
+ | `/tag` | Create colored tags and apply them to messages. View messages by tag. |
141
+ | `/rules` | Create email filtering rules. Set conditions (from address, subject contains) and actions (move to folder, mark as read, delete). |
142
+
143
+ ### Agent Commands
144
+
145
+ | Command | What It Does |
146
+ |---------|-------------|
147
+ | `/agents` | List all AI agents with their email address, API key (partially hidden), and owner name. |
148
+ | `/switch` | Switch the active agent. Changes which inbox you're viewing and which agent sends email. |
149
+ | `/deleteagent` | Delete an agent. Requires typing the agent's name to confirm (3 attempts). Archives all emails and generates a deletion report. |
150
+ | `/deletions` | View past agent deletion reports with email counts and top correspondents. |
151
+ | `/name` | Set a display name for the active agent. This appears in the From: header (e.g., "secretary from John"). |
152
+
153
+ ### Security Commands
154
+
155
+ | Command | What It Does |
156
+ |---------|-------------|
157
+ | `/spam` | View spam folder, report emails as spam, mark emails as not-spam, or get a detailed spam score showing which detection rules matched and their point values. |
158
+ | `/rules` | Create email filtering rules (also listed under Organization). |
159
+ | `/pending` | View blocked outbound emails that need approval. List all pending, approve to send, or reject to discard. Master key required — agents cannot approve their own emails. |
160
+
161
+ ### Chat & Agent Commands
162
+
163
+ | Command | What It Does |
164
+ |---------|-------------|
165
+ | `/chat` | **Chat directly with your OpenClaw AI agent** — opens a real-time chat session via WebSocket. Features bubble-style UI (agent left, user right), markdown rendering, elapsed timer during thinking, and multi-line input support. Uses Ed25519 device auth for secure gateway access. |
166
+ | `/tasks` | View pending tasks assigned to your agent. |
167
+ | `/msg` | Send a message to another AI agent by name. |
168
+ | `/assign` | Assign a task to another agent via the task queue. |
169
+
170
+ ### Gateway Commands
171
+
172
+ | Command | What It Does |
173
+ |---------|-------------|
174
+ | `/relay` | Search the connected relay account (Gmail/Outlook) and import specific emails into the local inbox. |
175
+ | `/setup` | Re-run the setup wizard. |
176
+ | `/status` | Show server health, gateway mode, and agent count. |
177
+ | `/openclaw` | Launch an OpenClaw terminal session. Opens in a new terminal window (macOS Terminal, or gnome-terminal/xterm/konsole on Linux). |
178
+
179
+ ### System Commands
180
+
181
+ | Command | What It Does |
182
+ |---------|-------------|
183
+ | `/help` | Show all available commands with descriptions. |
184
+ | `/clear` | Clear the screen. |
185
+ | `/exit` | Exit the shell (also `/quit`). Stops the server and cleans up. |
186
+
187
+ ---
188
+
189
+ ## Inbox Navigation
190
+
191
+ The inbox viewer (`/inbox`) is fully interactive:
192
+
193
+ - **Up/Down arrows** — move the cursor between emails (green arrow indicator)
194
+ - **Left arrow or `p`** — previous page
195
+ - **Right arrow or `n`** — next page
196
+ - **Enter** — open the selected email full-screen (press any key to return)
197
+ - **`v`** — toggle body previews on/off
198
+ - **Escape** — exit the inbox viewer
199
+
200
+ 10 emails per page. Unread emails show a cyan star. Colors rotate through 8 different colors for visual variety.
201
+
202
+ ---
203
+
204
+ ## Email Approval Workflow
205
+
206
+ This is one of the most important features. When an AI agent sends an email that the outbound security guard flags (containing passwords, API keys, personal information, etc.):
207
+
208
+ 1. The email is **blocked and stored** in the pending queue
209
+ 2. The **owner is notified** via a notification email to their relay address (Gmail/Outlook)
210
+ 3. The owner can approve or reject through the `/pending` command in the shell
211
+
212
+ But there's an easier way: the owner can simply **reply to the notification email**. Reply with "approve", "yes", "lgtm", "go ahead", "send", or "ok" to send the blocked email. Reply with "reject", "no", "deny", "cancel", or "block" to discard it. The relay polling system picks up the reply and acts on it automatically.
213
+
214
+ The relay polling acts like a persistent background job — it keeps checking for new messages on an exponential backoff schedule (starting at 30 seconds, growing to a cap of 5 minutes, resetting when mail arrives). This means the agent effectively has a follow-up mechanism: it can periodically check if its blocked email was approved and continue accordingly.
215
+
216
+ ---
217
+
218
+ ## Scheduled Emails
219
+
220
+ The `/schedule` command supports many time formats:
221
+
222
+ - **Quick presets:** 30 minutes, 1 hour, 3 hours, tomorrow 8am, tomorrow 9am
223
+ - **Custom dates:** `02-14-2026 3:30 PM EST`
224
+ - **Relative:** `in 30 minutes`, `in 2 hours`
225
+ - **Named:** `tomorrow 8am`, `tomorrow 2pm`
226
+ - **Day of week:** `next monday 9am`, `next friday 2pm`
227
+ - **Casual:** `tonight`, `this evening` (sends at 8 PM)
228
+
229
+ Timezone support includes: EST, EDT, CST, CDT, MST, MDT, PST, PDT, GMT, UTC, BST, CET, CEST, IST, JST, AEST, AEDT, and many more. The system automatically detects your local timezone as a default.
230
+
231
+ ---
232
+
233
+ ## Attachments
234
+
235
+ The shell supports file attachments in `/send`, `/reply`, and `/forward`:
236
+
237
+ - **Drag and drop** — drag a file from Finder/Explorer into the terminal
238
+ - **File path** — type or paste a file path (handles quotes, spaces, and `~` expansion)
239
+ - Files are base64-encoded before upload
240
+ - File sizes are displayed in KB
241
+ - You can attach multiple files to a single email
242
+
243
+ For downloading attachments, `/save` lets you pick individual attachments or save all at once.
244
+
245
+ ---
246
+
247
+ ## OpenClaw Integration
248
+
249
+ `agenticmail openclaw` is a 5-step setup command that integrates AgenticMail with the OpenClaw agent framework:
250
+
251
+ 1. Checks if Docker and Stalwart are already running (reuses existing infrastructure)
252
+ 2. Starts the API server if not already running
253
+ 3. **Agent selection** — shows existing agents with inbox/sent counts in an interactive arrow-key selector, or lets you create a new one
254
+ 4. Merges the AgenticMail plugin configuration into your `openclaw.json` (searches current directory and `~/.openclaw/`, supports JSON and JSONC formats)
255
+ 5. Offers to restart the OpenClaw gateway so the plugin activates immediately
256
+
257
+ ### Chat with Your AI Agent
258
+
259
+ Once set up, use `/chat` in the AgenticMail shell to talk directly to your OpenClaw agent:
260
+
261
+ - **Real-time WebSocket connection** to the OpenClaw gateway
262
+ - **Bubble-style UI** — agent messages left-aligned with gray borders, your messages right-aligned with blue borders
263
+ - **Markdown rendering** — bold, italic, code, headers, and bullet lists rendered in ANSI
264
+ - **Thinking indicator** — animated spinner with elapsed timer while the agent processes
265
+ - **Multi-line input** — Enter sends, `\` + Enter for new lines, arrow keys to navigate, backspace merges lines
266
+ - **Ed25519 device authentication** — secure keypair-based auth for full scope access
267
+ - **Esc to exit** — returns cleanly to the main shell
268
+
269
+ ### Smart Sub-Agent Spawning (`call_agent`)
270
+
271
+ The `call_agent` tool intelligently spawns sub-agents with:
272
+
273
+ - **Auto mode detection** — analyzes task complexity to choose light (simple math/lookups), standard (web research, file ops), or full (multi-agent coordination) mode
274
+ - **Dynamic timeouts** — light=60s, standard=180s, full=300s, max=600s
275
+ - **Dynamic tool discovery** — probes OpenClaw config at runtime to detect available tools (Brave search, web_fetch, etc.)
276
+ - **Web search fallback** — when Brave API isn't configured, sub-agents automatically use DuckDuckGo via `web_fetch`
277
+ - **Async mode** — `call_agent(async=true)` for long-running tasks (hours/days); agent runs independently and emails results when done
278
+
279
+ ---
280
+
281
+ ## Programmatic Usage
282
+
283
+ The package re-exports everything from `@agenticmail/core`, so you can use it as an SDK:
284
+
285
+ ```typescript
286
+ import {
287
+ AgenticMailClient,
288
+ MailSender,
289
+ MailReceiver,
290
+ parseEmail,
291
+ InboxWatcher,
292
+ AccountManager,
293
+ StalwartAdmin,
294
+ GatewayManager,
295
+ RelayGateway,
296
+ CloudflareClient,
297
+ TunnelManager,
298
+ DNSConfigurator,
299
+ DomainPurchaser,
300
+ getDatabase,
301
+ EmailSearchIndex,
302
+ type SendMailOptions,
303
+ type ParsedEmail,
304
+ type Agent,
305
+ type GatewayConfig,
306
+ } from 'agenticmail';
307
+ ```
308
+
309
+ See the [@agenticmail/core README](https://github.com/agenticmail/agenticmail/tree/main/packages/core) for complete SDK documentation.
310
+
311
+ ---
312
+
313
+ ## Environment Variables
314
+
315
+ Create a `.env` file in your project root or set these in your environment:
316
+
317
+ ```bash
318
+ # === Required ===
319
+ AGENTICMAIL_MASTER_KEY=mk_your_key # Admin API key
320
+
321
+ # === Stalwart Mail Server ===
322
+ STALWART_ADMIN_USER=admin # Stalwart admin username
323
+ STALWART_ADMIN_PASSWORD=changeme # Stalwart admin password
324
+ STALWART_URL=http://localhost:8080 # Stalwart HTTP admin URL
325
+
326
+ # === SMTP/IMAP (local Stalwart) ===
327
+ SMTP_HOST=localhost # SMTP host
328
+ SMTP_PORT=587 # SMTP submission port
329
+ IMAP_HOST=localhost # IMAP host
330
+ IMAP_PORT=143 # IMAP port
331
+
332
+ # === Optional ===
333
+ AGENTICMAIL_API_PORT=3100 # API port (default: 3100)
334
+ AGENTICMAIL_DATA_DIR=~/.agenticmail # Data directory
335
+
336
+ # === Gateway (optional) ===
337
+ RELAY_PROVIDER=gmail # gmail or outlook
338
+ RELAY_EMAIL=you@gmail.com # Relay email
339
+ RELAY_PASSWORD=xxxx xxxx xxxx xxxx # App password
340
+ CLOUDFLARE_API_TOKEN=your_token # For domain mode
341
+ CLOUDFLARE_ACCOUNT_ID=your_account # For domain mode
342
+ AGENTICMAIL_DOMAIN=yourdomain.com # Custom domain
343
+
344
+ # === Debug ===
345
+ # AGENTICMAIL_DEBUG=1 # Verbose per-message logging
346
+ ```
347
+
348
+ ---
349
+
350
+ ## License
351
+
352
+ [MIT](./LICENSE) - Ope Olatunji ([@ope-olatunji](https://github.com/ope-olatunji))