邮件分选:智能 IMAP 收件箱分类 - Openclaw Skills

作者:互联网

2026-03-25

AI教程

什么是 邮件分选?

邮件分选(Email Triage)技能是一个强大的自动化工具,旨在通过扫描 IMAP 账户并根据重要性对邮件进行分类来管理高流量收件箱。通过 Ollama 集成本地大语言模型(LLM),它提供智能分类,能够区分紧急故障、需要回复的业务咨询以及一般的通知信息。这使其成为 Openclaw Skills 用户在无需手动筛选的情况下提取关键信息的必备组件。

该技能在构建时充分考虑了可靠性,采用了双层分类系统。它优先尝试高保真 AI 分析,但也包含一个稳健的基于关键词的启发式回退机制,以确保在本地模型离线时系统仍能正常运行。此工具非常适合想要在原始邮件数据与可执行的代理驱动工作流之间建立桥梁的开发人员和高级用户。

下载入口:https://github.com/openclaw/skills/tree/main/skills/briancolinger/email-triage

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install email-triage

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 email-triage。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

邮件分选 应用场景

  • 在拥挤的收件箱中自动检测紧急服务器警报或安全通知。
  • 构建一个 AI 驱动的个人助理,总结需要回复的邮件。
  • 从高优先级的业务沟通渠道中过滤营销噪音和垃圾邮件。
  • 创建程序化桥梁,将优先处理的邮件数据输入到其他自动化工作流中。
邮件分选 工作原理
  1. 脚本启动到配置的 IMAP 服务器的安全 SSL 连接,以获取最新的未读邮件。
  2. 去重过程根据本地状态检查 Message-ID 或主题哈希,以防止重复处理。
  3. 内容被发送到本地 Ollama 实例进行语义分析;如果不可用,脚本将使用内部启发式规则。
  4. 分类结果(包括优先级类别和理由)被保存到持久化 JSON 状态文件中。
  5. 用户可以生成报告以查看特定的高优先级类别,如“紧急”或“需要回复”。
  6. 处理过的邮件被标记为“已呈现”,以确保后续报告仅关注新的、未处理的通信。

邮件分选 配置指南

要开始使用此 Openclaw Skills 技能,请确保您已安装 Python 3.10+ 并准备好 IMAP 凭据。如果使用 Gmail 等提供商,您可能需要应用专用密码。

# 安装先决条件并配置环境变量
export IMAP_HOST='imap.yourserver.com'
export IMAP_USER='yourname@example.com'
export IMAP_PASS='yourpassword'

# 运行初始扫描以分类未读邮件
python3 scripts/email/email-triage.py scan

# 查看紧急邮件报告
python3 scripts/email/email-triage.py report

邮件分选 数据架构与分类体系

该技能在本地 JSON 文件中管理其状态,通常位于 ./data/email-triage.json。此文件是所有已处理通信的唯一事实来源。

属性 类型 描述
category 字符串 优先级标签(urgent, needs-response, informational, spam)。
reason 字符串 简要说明邮件为何被归入该类别。
surfaced 布尔值 跟踪邮件是否已包含在报告输出中。
id 字符串 源自 Message-ID 或内容哈希的唯一标识符。
timestamp ISO8601 邮件最后一次分选的日期和时间。
name: email-triage
version: 1.0.1
description: IMAP email scanning and triage with AI classification via a local Ollama LLM. Scans unread emails, categorizes them as urgent, needs-response, informational, or spam, and surfaces important messages for agent consumption. Works standalone with heuristic fallback — Ollama optional but recommended.
metadata:
  openclaw:
    requires:
      bins: ["python3"]

Email Triage

Scan your IMAP inbox, classify emails into priority categories, and surface the ones that need attention. Uses a local LLM (Ollama) for intelligent classification with a rule-based heuristic fallback when Ollama is unavailable.

Prerequisites

  • Python 3.10+
  • IMAP-accessible email account (Gmail, Fastmail, self-hosted, etc.)
  • Ollama (optional) — for AI-powered classification. Without it, the script uses keyword-based heuristics that still work well for common patterns.

Categories

Icon Category Description
?? urgent Outages, security alerts, legal, payment failures, time-critical
?? needs-response Business inquiries, questions, action items requiring a reply
?? informational Receipts, confirmations, newsletters, automated notifications
? spam Marketing, promotions, unsolicited junk

Configuration

All configuration is via environment variables:

Variable Required Default Description
IMAP_HOST ? IMAP server hostname
IMAP_PORT 993 IMAP port (SSL)
IMAP_USER ? IMAP username / email address
IMAP_PASS ? IMAP password or app-specific password
EMAIL_TRIAGE_STATE ./data/email-triage.json Path to the JSON state file
OLLAMA_URL http://127.0.0.1:11434 Ollama API endpoint
OLLAMA_MODEL qwen2.5:7b Ollama model for classification

Directories Written

  • EMAIL_TRIAGE_STATE (default: ./data/email-triage.json) — Persistent state file tracking classified emails and surfacing status

Commands

# Scan inbox and classify new unread emails
python3 scripts/email/email-triage.py scan

# Scan with verbose output (shows each classification)
python3 scripts/email/email-triage.py scan --verbose

# Dry run — scan and classify but don't save state
python3 scripts/email/email-triage.py scan --dry-run

# Show unsurfaced important emails (urgent + needs-response)
python3 scripts/email/email-triage.py report

# Same as report but JSON output (for programmatic use)
python3 scripts/email/email-triage.py report --json

# Mark reported emails as surfaced (so they don't appear again)
python3 scripts/email/email-triage.py mark-surfaced

# Show triage statistics
python3 scripts/email/email-triage.py stats

How It Works

  1. Connects to IMAP over SSL and fetches unread messages (up to 20 per scan).
  2. Deduplicates by Message-ID (or a hash of subject + sender as fallback) so emails are never classified twice.
  3. Classifies each email using Ollama if available, otherwise falls back to keyword heuristics.
  4. Stores state in a local JSON file — tracks category, reason, and whether the email has been surfaced.
  5. report surfaces only unsurfaced urgent and needs-response emails, sorted by priority.
  6. mark-surfaced flags reported emails so they won't appear in future reports.
  7. Auto-prunes state to the most recent 200 entries to prevent unbounded growth.

Integration Tips

  • Heartbeat / cron: Run scan periodically, then report --json to check for items needing attention.
  • Agent workflow: scanreport --json → act on results → mark-surfaced.
  • Without Ollama: The heuristic classifier handles common patterns (automated notifications, marketing, urgent keywords) well. Ollama adds nuance for ambiguous emails.
  • App passwords: If your provider uses 2FA, generate an app-specific password for IMAP access.