邮件摘要与联系人画像技能:从IMAP邮箱拉取邮件或解析本地导出文件(.pst/.mbox/.msg),生成联系人画像报告(HTML)
电子邮件总览器 + 联系配置器是一项面向实际任务的技能,主要用于三独立阶段 —— 根据需要运行任何子集;每个阶段从 / 写入文件( 或 stdin/ stdout) , 因此它们可以自由编曲。
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
三个独立阶段 —— 可根据实际需求运行任意子集:
[数据源] [分析] [投递]
fetch_imap.py ──→ ──→
parse_file.py ──→ build_report.py ──→ send_report.py
→ .html + .xlsx
每个阶段均通过文件(或 stdin/stdout)读取/写入数据,因此可自由组合使用。
# Python 依赖 pip install -r requirements.txt # Node.js 依赖(仅用于原生 .pst 解析) cd scripts && npm install && cd ..
fetch_imap.py —— 从实时 IMAP 邮箱拉取邮件export EMAIL_USER=you@163.com
export EMAIL_PASS=your-app-password
# 拉取最近 7 天(仅收件箱)→ emails.json
python3 scripts/fetch_imap.py --days 7 --output emails.json
# 拉取指定日期范围(收件箱 + 已发送)
python3 scripts/fetch_imap.py --since 2026-03-01 --until 2026-03-28
--with-sent --preset 163 --output emails.json
# 直接管道传输至 build_report.py(不生成中间文件)
python3 scripts/fetch_imap.py --days 30 | python3 scripts/build_report.py --output report
| 参数 | 默认值 | 说明 |
|---|---|---|
--days N |
7 | 拉取最近 N 天的邮件。若设置了 --since,则该参数被忽略。 |
--since DATE |
— | 起始日期(含),格式为 YYYY-MM-DD |
--until DATE |
— | 结束日期(不含),格式为 YYYY-MM-DD(默认为今日) |
--max N |
200 | 每文件夹最多拉取邮件数 |
--folder NAME |
INBOX | 收件箱文件夹名称 |
--preset NAME |
163 | 邮箱预设配置:163 | qq | exmail | gmail | outlook |
--with-sent |
关闭 | 同时拉取“已发送”文件夹(推荐用于关系分析) |
--output FILE |
stdout | 将 JSON 写入指定文件;若省略则输出至 stdout |
支持的预设配置:
| 预设 | IMAP 服务器 | 已发送文件夹名 |
|---|---|---|
163 |
imap.163.com:993 | 已发送 |
qq |
imap.qq.com:993 | Sent Messages |
exmail |
imap.exmail.qq.com:993 | Sent Messages |
gmail |
imap.gmail.com:993 | [Gmail]/Sent Mail |
outlook |
outlook.office365.com:993 | Sent Items |
parse_file.py —— 解析本地邮件导出文件# 解析 .pst 文件(原生引擎,无需系统级安装) python3 scripts/parse_file.py --pst ~/Downloads/archive.pst --output emails.json # 解析 .mbox 文件(收件箱 + 已发送) python3 scripts/parse_file.py --mbox Inbox.mbox --sent-mbox Sent.mbox --output emails.json # 解析 .msg 文件目录,并按日期过滤 python3 scripts/parse_file.py --msg-dir ./exported/ --since 2026-01-01 --output emails.json # 管道传输至 build_report.py python3 scripts/parse_file.py --pst archive.pst | python3 scripts/build_report.py --output report
| 参数 | 默认值 | 说明 |
|---|---|---|
--pst FILE |
— | Outlook .pst 归档文件 |
--mbox FILE |
— | Unix mbox 文件 |
--msg-dir DIR |
— | .msg 文件所在目录 |
--sent-mbox FILE |
— | 额外的已发送 mbox 文件(需配合 --mbox 使用) |
--pst-engine |
auto | auto | native | readpst |
--days N |
all | 仅包含最近 N 天的邮件 |
--since DATE |
— | 起始日期(含),格式为 YYYY-MM-DD |
--until DATE |
— | 结束日期(不含),格式为 YYYY-MM-DD |
--max N |
500 | 最多加载邮件数 |
--output FILE |
stdout | 将 JSON 写入指定文件;若省略则输出至 stdout |
PST 解析引擎:
| 引擎 | 参数 | 依赖 |
|---|---|---|
| 原生(默认) | --pst-engine native |
cd scripts && npm install |
| Readpst | --pst-engine readpst |
apt install pst-utils 或 brew install libpst |
| 自动选择 | --pst-engine auto |
优先尝试原生引擎,失败后回退至 readpst |
build_report.py —— 邮件分析 → HTML + Excel 报告# 从文件读取
python3 scripts/build_report.py --input emails.json --output report
# 显式指定所有者(适用于分析他人 PST)
python3 scripts/build_report.py --input emails.json --output report
--owner xiang-xiang.hu@connect.polyu.hk
# 从 stdin 读取(由第一阶段管道传入)
python3 scripts/fetch_imap.py --days 30 | python3 scripts/build_report.py --output report
| 参数 | 默认值 | 说明 |
|---|---|---|
--input FILE |
stdin | 第一阶段生成的 emails JSON 文件路径 |
--output PREFIX |
contact_report | 输出路径前缀。将生成 和 |
--owner EMAIL |
自动推断 | 邮箱所有者地址。若省略则自动检测。 |
输出文件:
.html —— 自包含 HTML 报告(可在浏览器中打开,或作为邮件附件).xlsx —— 同等数据的 Excel 表格报告列名:# / 首选姓名 / 邮箱 / 公司 / 职位 / 主题摘要 / 来源 / 往来邮件数(接收/发送)
send_report.py —— 通过 SMTP 发送报告文件export EMAIL_USER=you@163.com
export EMAIL_PASS=your-app-password
# 向收件人发送 HTML + Excel
python3 scripts/send_report.py
--html report.html --xlsx report.xlsx --to friend@example.com
# 发送给自己(EMAIL_USER)
python3 scripts/send_report.py --html report.html --xlsx report.xlsx
# 仅发送 HTML(不带附件)
python3 scripts/send_report.py --html report.html --to friend@example.com
# 自定义邮件主题
python3 scripts/send_report.py --html report.html --subject "March Contact Report"
| 参数 | 默认值 | 说明 |
|---|---|---|
--html FILE |
必填 | 用作邮件正文的 HTML 文件 |
--xlsx FILE |
— | 待附加的 Excel 文件(可选) |
--to ADDR |
EMAIL_USER | 收件人地址 |
--subject STR |
自动 | 邮件主题(若省略则自动生成) |
--preset NAME |
163 | SMTP 预设配置:163 | qq | exmail | gmail | outlook |
| 文件 | 提供功能 |
|---|---|
_core.py |
decode_header, parse_addr, get_domain, strip_html, html_esc, get_body |
_analyze.py |
infer_owner, build_contacts,以及域名/公司/职位/姓名推断逻辑 |
_render.py |
build_report_html, build_excel, SMTP_MAP |
export EMAIL_USER=you@163.com export EMAIL_PASS=your-app-password python3 scripts/fetch_imap.py --days 30 --with-sent --output /tmp/emails.json python3 scripts/build_report.py --input /tmp/emails.json --output /tmp/report python3 scripts/send_report.py --html /tmp/report.html --xlsx /tmp/report.xlsx --preset 163
python3 scripts/parse_file.py --pst ~/Downloads/archive.pst --output /tmp/emails.json
python3 scripts/build_report.py --input /tmp/emails.json --output /tmp/report
EMAIL_USER=sender@163.com EMAIL_PASS=xxx
python3 scripts/send_report.py --html /tmp/report.html --xlsx /tmp/report.xlsx
--to recipient@example.com
python3 scripts/parse_file.py --pst archive.pst | python3 scripts/build_report.py --output /tmp/report
python3 scripts/parse_file.py --mbox Inbox.mbox --output /tmp/emails.json python3 scripts/build_report.py --input /tmp/emails.json --output /tmp/report # 在浏览器中打开 /tmp/report.html
将邮件 JSON 加载至 AI 上下文后,可使用以下模板:
🔥 第一部分 —— 重要事项与待办项 🚨 [紧急] 主题 — 发件人 — 日期 | 摘要 | 行动项 | 截止时间 ⚡ [重要] 主题 — 发件人 — 日期 | 摘要 | 行动项 📌 [备注] 主题 — 发件人 — 日期 | 摘要 📊 第二部分 —— 按发件人 / 主题分组 ✅ 第三部分 —— 待办清单 📅 第四部分 —— 时间线(YYYY-MM-DD 发件人 → 主题:摘要)
按总交互次数排序。对每位联系人:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 👤 排名 #N | 姓名 <邮箱> 总计:N(接收:N / 发送:N) 🧑 性别 M/F/未知 置信度:高/中/低 依据:… 💼 职位 … 依据:域名 / 签名 / 关键词 🔗 关系 同事 / 客户 / 机构 / 陌生人 方向 双向 / 所有者发起 / 联系人发起 📝 主题 • 主题 1 • 主题 2 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
热度标尺:🔥 高频(≥10) · ⚡ 活跃(5–9) · 💬 中等(2–4) · 🌙 低频(1)
fetch_imap.py 向 163/188 邮箱服务器发送 RFC 2971 ID 命令;该命令在其他服务器上无影响相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习
最新文章