clawMail Skill
You are an email management agent with multi-account IMAP/SMTP support. You can
fetch, read, search, process, compose, send, reply, forward, move, and manage
emails, drafts, and folders across multiple email accounts.
Multi-Account Model
- - Account profiles: Each account has its own IMAP/SMTP credentials, mailboxes,
fetch limits, archival settings, and processing rules.
- - Default account: One account is designated as the default. Any script invoked
without
--account uses the default automatically.
- - SMTP fallback: If an account's SMTP server fails, the system automatically
retries via a configured fallback relay.
- - IMAP Outbox: Messages are staged in a temporary Outbox folder before SMTP
delivery. If SMTP fails, the message stays in Outbox for retry by the heartbeat.
- - Per-account + global rules: Each account has its own rules, plus global rules
that apply to all accounts.
- - OAuth2: Accounts can use OAuth2 (XOAUTH2) authentication instead of passwords.
- Dated-folder archival:
archive_mail.py and the heartbeat honor per-account
archive_root/
archive_frequency defaults so messages routed to the
archive
action land in folders such as
Archive-202603,
Archive-W09, or
Archive-20260315.
Security
- - TLS 1.2+: All IMAP and SMTP connections enforce TLS 1.2 or higher.
- Hardened ciphers: Only ECDHE+AESGCM, ECDHE+CHACHA20, DHE+AESGCM, and
DHE+CHACHA20 cipher suites are allowed. Weak ciphers (MD5, RC4, 3DES, DSS)
are explicitly blocked.
- - Certificate verification: Hostname checking and certificate validation are
always enabled.
- - RFC 5322 compliance: All outgoing emails include required Date, Message-ID,
and MIME-Version headers automatically.
- - Secure credential storage: Passwords in config support 1Password CLI
(
op://vault/item/field), macOS Keychain (
keychain://service/account),
and environment variables (
env://VAR_NAME).
Available Scripts
All scripts are in the scripts/ directory. Run with
python3 scripts/<name>.py from the skill root. Every script accepts
--account <name> to target a specific account.
Core Scripts
| Script | Purpose |
|---|
| INLINECODE14 | Fetch emails from an IMAP folder |
| INLINECODE15 |
Read/render an email by Message-ID; save attachments to disk |
|
scripts/search_mail.py | Search emails by subject, sender, body, date, flags |
|
scripts/send_mail.py | Send rich HTML emails via SMTP (Outbox + fallback); attach files |
|
scripts/compose_mail.py | Compose rich HTML emails from templates; attach files |
|
scripts/reply_mail.py | Reply to an email with original-message quoting |
|
scripts/forward_mail.py | Forward an email inline-quoted or with attachments |
|
scripts/draft_mail.py | Save, list, resume, or send drafts via IMAP Drafts folder |
|
scripts/process_mail.py | Run emails through the rule-based processing pipeline |
|
scripts/manage_folders.py | List, create, delete, rename, and move IMAP folders |
|
scripts/move_mail.py | Move emails between IMAP folders (batch support) |
|
scripts/heartbeat.py | Run a full heartbeat cycle (drains Outbox, fetches, processes) |
|
scripts/idle_monitor.py | Monitor a mailbox via IMAP IDLE (push notifications) |
|
scripts/retry_send.py | Retry sending messages stuck in the IMAP Outbox |
|
scripts/calendar_invite.py | Compose and send iCalendar meeting invitations |
|
scripts/mail_merge.py | Batch personalised sends from template + CSV/JSON data |
|
scripts/thread_mail.py | Group messages into conversation threads |
|
scripts/archive_mail.py | Auto-archive old messages into dated folders (daily/weekly/monthly/yearly) |
Library Modules
| Module | Purpose |
|---|
| INLINECODE32 | IMAP client with IDLE, search, folder management, TLS 1.2+ |
| INLINECODE33 |
SMTP client with TLS 1.2+, RFC 5322, OAuth2, MIME building |
|
scripts/lib/composer.py | Rich HTML email composer with templates, reply, forward |
|
scripts/lib/processor.py | Rule-based processing pipeline with webhook actions |
|
scripts/lib/account_manager.py | Multi-account manager with SMTP fallback and Outbox |
|
scripts/lib/outbox.py | IMAP Outbox — temporary folder for reliable delivery |
|
scripts/lib/credential_store.py | Secure credential storage (1Password, Keychain, env) |
|
scripts/lib/pool.py | Connection pool for IMAP/SMTP reuse |
|
scripts/lib/send_queue.py | Legacy file-backed send queue (superseded by Outbox) |
|
scripts/lib/smime.py | S/MIME signing and encryption |
|
scripts/lib/oauth2.py | OAuth2 (XOAUTH2) token management |
|
scripts/lib/models.py | Data models (EmailMessage, EmailAddress, etc.) |
Reference Documents
| Reference | When to read |
|---|
| INLINECODE44 | API overview, all script arguments and output formats |
| INLINECODE45 |
Available email templates and template variables |
|
references/RULES.md | How to configure processing rules |
|
ROADMAP.md | Feature roadmap and progress tracker |
Quick Start
Fetching Mail
CODEBLOCK0
Sending Rich Emails
Messages are staged in a temporary IMAP Outbox folder, sent via SMTP
(with automatic fallback), then removed from Outbox on success.
CODEBLOCK1
Replying and Forwarding
CODEBLOCK2
Searching Emails
CODEBLOCK3
Working with Drafts
CODEBLOCK4
Outbox & Send Retry
CODEBLOCK5
Heartbeat Cycle
The heartbeat drains each account's Outbox, then fetches and processes mail:
CODEBLOCK6
Archiving Old Messages
CODEBLOCK7
Archiving honors archive_root / archive_frequency settings (defaults: Archive, monthly). The heartbeat and any rule with the archive action move the message into folders named Archive-202603, Archive-W09, or Archive-20260315 based on the configured cadence.
Calendar Invitations
CODEBLOCK8
Mail Merge
CODEBLOCK9
Configuration
Create a config.yaml from assets/config.example.yaml:
CODEBLOCK10
You can also define archive_root (e.g., Archive) and archive_frequency (daily, weekly, monthly, yearly) either globally or per- account. These defaults drive both the archive_mail.py script and the heartbeat's handling of the archive rule action so that archived messages consistently live under folders like Archive-202603, Archive-W09, or Archive-20260315.
Secure Credential Storage
Passwords in config support four backends:
| Scheme | Backend | Example |
|---|
| INLINECODE70 | 1Password CLI | INLINECODE71 |
| INLINECODE72 |
macOS Keychain |
"keychain://imap.gmail.com/alice" |
|
env:// | Environment variable |
"env://GMAIL_APP_PASSWORD" |
|
(plain text) | Literal value |
"my-password" (logs a warning) |
OAuth2 Authentication (Gmail, Outlook 365)
For providers that require OAuth2, set auth: oauth2 on the IMAP/SMTP block:
CODEBLOCK11
Legacy Single-Account Config
Flat imap: / smtp: at root is automatically treated as a single account
named "default".
clawMail 技能
您是一个支持多账户 IMAP/SMTP 的邮件管理代理。您可以跨多个电子邮件账户获取、阅读、搜索、处理、撰写、发送、回复、转发、移动和管理邮件、草稿及文件夹。
多账户模型
- - 账户配置文件:每个账户拥有独立的 IMAP/SMTP 凭据、邮箱、获取限制、归档设置和处理规则。
- 默认账户:指定一个账户为默认账户。任何未使用 --account 参数调用的脚本将自动使用默认账户。
- SMTP 回退:如果某个账户的 SMTP 服务器失败,系统将通过配置的回退中继自动重试。
- IMAP 发件箱:邮件在 SMTP 投递前暂存于临时发件箱文件夹。若 SMTP 失败,邮件将保留在发件箱中,由心跳机制重试。
- 按账户 + 全局规则:每个账户拥有自己的规则,同时全局规则适用于所有账户。
- OAuth2:账户可使用 OAuth2(XOAUTH2)认证替代密码。
- 按日期归档:archivemail.py 和心跳机制遵循各账户的 archiveroot/archive_frequency 默认值,因此路由到 archive 操作的邮件将被放入诸如 Archive-202603、Archive-W09 或 Archive-20260315 等文件夹。
安全性
- - TLS 1.2+:所有 IMAP 和 SMTP 连接强制使用 TLS 1.2 或更高版本。
- 强化密码套件:仅允许 ECDHE+AESGCM、ECDHE+CHACHA20、DHE+AESGCM 和 DHE+CHACHA20 密码套件。弱密码套件(MD5、RC4、3DES、DSS)被明确阻止。
- 证书验证:始终启用主机名检查和证书验证。
- RFC 5322 合规:所有外发邮件自动包含必需的 Date、Message-ID 和 MIME-Version 标头。
- 安全凭据存储:配置中的密码支持 1Password CLI(op://vault/item/field)、macOS 钥匙串(keychain://service/account)和环境变量(env://VAR_NAME)。
可用脚本
所有脚本位于 scripts/ 目录。从技能根目录使用 python3 scripts/.py 运行。每个脚本接受 --account 参数以指定目标账户。
核心脚本
| 脚本 | 用途 |
|---|
| scripts/fetchmail.py | 从 IMAP 文件夹获取邮件 |
| scripts/readmail.py |
按 Message-ID 阅读/渲染邮件;将附件保存到磁盘 |
| scripts/search_mail.py | 按主题、发件人、正文、日期、标志搜索邮件 |
| scripts/send_mail.py | 通过 SMTP 发送富 HTML 邮件(发件箱 + 回退);附加文件 |
| scripts/compose_mail.py | 从模板撰写富 HTML 邮件;附加文件 |
| scripts/reply_mail.py | 回复邮件并引用原邮件 |
| scripts/forward_mail.py | 以内联引用或附件形式转发邮件 |
| scripts/draft_mail.py | 通过 IMAP 草稿文件夹保存、列出、恢复或发送草稿 |
| scripts/process_mail.py | 通过基于规则的处理流水线处理邮件 |
| scripts/manage_folders.py | 列出、创建、删除、重命名和移动 IMAP 文件夹 |
| scripts/move_mail.py | 在 IMAP 文件夹之间移动邮件(支持批量) |
| scripts/heartbeat.py | 运行完整心跳周期(清空发件箱、获取、处理) |
| scripts/idle_monitor.py | 通过 IMAP IDLE 监控邮箱(推送通知) |
| scripts/retry_send.py | 重试发送卡在 IMAP 发件箱中的邮件 |
| scripts/calendar_invite.py | 撰写并发送 iCalendar 会议邀请 |
| scripts/mail_merge.py | 从模板 + CSV/JSON 数据批量发送个性化邮件 |
| scripts/thread_mail.py | 将邮件分组为会话线程 |
| scripts/archive_mail.py | 自动将旧邮件归档到按日期命名的文件夹(每日/每周/每月/每年) |
库模块
| 模块 | 用途 |
|---|
| scripts/lib/imapclient.py | 支持 IDLE、搜索、文件夹管理、TLS 1.2+ 的 IMAP 客户端 |
| scripts/lib/smtpclient.py |
支持 TLS 1.2+、RFC 5322、OAuth2、MIME 构建的 SMTP 客户端 |
| scripts/lib/composer.py | 支持模板、回复、转发的富 HTML 邮件撰写器 |
| scripts/lib/processor.py | 支持 webhook 操作的基于规则的处理流水线 |
| scripts/lib/account_manager.py | 支持 SMTP 回退和发件箱的多账户管理器 |
| scripts/lib/outbox.py | IMAP 发件箱——用于可靠投递的临时文件夹 |
| scripts/lib/credential_store.py | 安全凭据存储(1Password、钥匙串、环境变量) |
| scripts/lib/pool.py | 用于 IMAP/SMTP 复用的连接池 |
| scripts/lib/send_queue.py | 旧版基于文件的发送队列(已被发件箱取代) |
| scripts/lib/smime.py | S/MIME 签名和加密 |
| scripts/lib/oauth2.py | OAuth2(XOAUTH2)令牌管理 |
| scripts/lib/models.py | 数据模型(EmailMessage、EmailAddress 等) |
参考文档
| 参考文档 | 何时阅读 |
|---|
| references/REFERENCE.md | API 概述、所有脚本参数和输出格式 |
| references/TEMPLATES.md |
可用的邮件模板和模板变量 |
| references/RULES.md | 如何配置处理规则 |
| ROADMAP.md | 功能路线图和进度跟踪器 |
快速入门
获取邮件
bash
python3 scripts/fetch_mail.py --config config.yaml
python3 scripts/fetch_mail.py --account personal --unread-only --format cli --config config.yaml
发送富邮件
邮件暂存于临时 IMAP 发件箱文件夹,通过 SMTP 发送(自动回退),成功后从发件箱移除。
bash
python3 scripts/send_mail.py \
--to recipient@example.com \
--subject Weekly Report \
--body
Here are this weeks results.
\
--template default \
--attach report.pdf \
--config config.yaml
回复和转发
bash
python3 scripts/reply_mail.py --message-id --body Thanks! --config config.yaml
python3 scripts/forward_mail.py --message-id --to colleague@x.com --config config.yaml
搜索邮件
bash
python3 scripts/search_mail.py --subject invoice --unseen --config config.yaml
python3 scripts/search_mail.py --criteria (FROM alice@x.com SINCE 01-Jan-2026) --config config.yaml
处理草稿
bash
python3 scripts/draft_mail.py --action save --to user@x.com --subject WIP --body ... --config config.yaml
python3 scripts/draft_mail.py --action list --format cli --config config.yaml
python3 scripts/draft_mail.py --action send --message-id --config config.yaml
发件箱和发送重试
bash
python3 scripts/retry_send.py --config config.yaml
python3 scripts/retry_send.py --config config.yaml --list
心跳周期
心跳机制清空每个账户的发件箱,然后获取和处理邮件:
bash
python3 scripts/heartbeat.py --config config.yaml
python3 scripts/heartbeat.py --config config.yaml --account work
归档旧邮件
bash
python3 scripts/archive_mail.py --config config.yaml --days 90 --frequency monthly
python3 scripts/archive_mail.py --config config.yaml --days 30 --frequency daily --archive-root Old Mail --dry-run --format cli
归档遵循 archiveroot / archivefrequency 设置(默认值:Archive、monthly)。心跳机制和任何包含 archive 操作的规则将邮件移动到根据配置节奏命名的文件夹,如 Archive-