Email Manager Skill
This skill provides complete email management using your Postfix/Dovecot infrastructure.
📋 Configuration
Edit config.json in the skill directory:
CODEBLOCK0
📨 Available Operations
List folders
CODEBLOCK1
Example output:
CODEBLOCK2
List emails
CODEBLOCK3
Read email
CODEBLOCK4
Save draft
CODEBLOCK5
List drafts
CODEBLOCK6
Update draft
CODEBLOCK7
Send email
CODEBLOCK8
Send draft
CODEBLOCK9
Flag/star email
CODEBLOCK10
Move email
CODEBLOCK11
Create folder
CODEBLOCK12
Delete email
CODEBLOCK13
Empty trash
CODEBLOCK14
Search emails
CODEBLOCK15
Spam operations
CODEBLOCK16
🔍 Folder Auto-Detection
The skill automatically detects folder names for:
- - Inbox: INBOX, Inbox
- Drafts: Drafts, INBOX.Drafts, Draft
- Sent: Sent, Sent Messages, INBOX.Sent
- Trash: Trash, Deleted, INBOX.Trash
- Junk/Spam: Junk, Spam, INBOX.Junk, INBOX.Spam, Bulk
- Archive: Archive, Archives, INBOX.Archive
📁 Folder Name Handling
The skill cleans up folder names for display by removing IMAP flags like \HasNoChildren and quotes. For raw folder data with flags:
CODEBLOCK17
Example JSON output:
CODEBLOCK18
🤖 AI Usage Examples
Always use --output json when parsing results:
CODEBLOCK19
✅ Testing
Test your configuration:
CODEBLOCK20
All operations are non-interactive and suitable for automation.
🚀 Setup Instructions
CODEBLOCK21
📝 Common Spam Folder Names
Different Dovecot configurations use different spam folder names:
- - Junk (most common)
- Spam
- INBOX.Junk
- INBOX.Spam
- Bulk
- Junk E-mail
Set it explicitly in config.json if auto-detection doesn't work:
CODEBLOCK22
🎯 Key Benefits
- - ✅ Zero dependencies - Uses only Python standard library
- ✅ No virtualenv needed - Works with system Python
- ✅ JSON config - Easy to edit, no parsing libraries needed
- ✅ Non-interactive - Perfect for AI automation
- ✅ Full feature set - Drafts, send, folders, flags, move, delete, spam
- ✅ Debian/Ubuntu compatible - No "externally-managed-environment" errors
技能名称: email-manager
详细描述:
电子邮件管理技能
该技能利用您的Postfix/Dovecot基础设施提供完整的电子邮件管理功能。
📋 配置
编辑技能目录中的config.json文件:
json
{
email_address: your-email@domain.com,
email_password: your-password,
imap_server: mail.yourdomain.com,
smtp_server: mail.yourdomain.com
}
📨 可用操作
列出文件夹
bash
python3 scripts/imap_utils.py list-folders
python3 scripts/imap_utils.py list-folders --output json
输出示例:
📁 可用文件夹:
• 草稿 📝 DRAFTS
• 已发送 📤 SENT
• 垃圾箱 🗑️ TRASH
• 垃圾邮件 📧 SPAM
• 收件箱 📥 INBOX
• 归档
• 项目/客户A
列出邮件
bash
python3 scripts/imap_utils.py list --folder INBOX --limit 10
python3 scripts/imap_utils.py list --flagged-only --output json
阅读邮件
bash
python3 scripts/imap_utils.py read --message-id 1234
python3 scripts/imap_utils.py read --message-id 1234 --output json
保存草稿
bash
python3 scripts/imap_utils.py save-draft \
--to user@example.com \
--subject 草稿主题 \
--body 草稿内容
列出草稿
bash
python3 scripts/imap_utils.py list-drafts
python3 scripts/imap_utils.py list-drafts --output json
更新草稿
bash
python3 scripts/imap_utils.py update-draft \
--draft-id 1234 \
--subject 更新后的主题 \
--body 更新后的内容
发送邮件
bash
python3 scripts/smtp_utils.py send \
--to user@example.com \
--subject 测试 \
--body 你好
发送草稿
bash
python3 scripts/smtp_utils.py send-draft --draft-id 1234
标记/星标邮件
bash
python3 scripts/imap_utils.py flag --message-id 1234 --add
python3 scripts/imap_utils.py flag --message-id 1234 --remove
python3 scripts/imap_utils.py list --flagged-only
移动邮件
bash
python3 scripts/imap_utils.py move \
--message-id 1234 \
--from-folder INBOX \
--to-folder Projects
创建文件夹
bash
python3 scripts/imap_utils.py create-folder --name 新文件夹
删除邮件
bash
python3 scripts/imap_utils.py delete --message-id 1234
清空垃圾箱
bash
python3 scripts/imap_utils.py empty-trash
搜索邮件
bash
python3 scripts/imap_utils.py search --query FROM user@example.com
python3 scripts/imap_utils.py search --query subject:meeting --output json
垃圾邮件操作
bash
列出垃圾邮件
python3 scripts/imap_utils.py list-spam
python3 scripts/imap_utils.py list-spam --output json
标记为垃圾邮件
python3 scripts/imap_utils.py mark-spam --message-id 1234
python3 scripts/imap_utils.py mark-spam --message-id 1234 --from-folder INBOX
标记为非垃圾邮件
python3 scripts/imap_utils.py mark-ham --message-id 1234
python3 scripts/imap_utils.py mark-ham --message-id 1234 --from-folder Junk
清空垃圾邮件文件夹
python3 scripts/imap_utils.py empty-spam
🔍 文件夹自动检测
该技能自动检测以下文件夹名称:
- - 收件箱: INBOX, Inbox
- 草稿: Drafts, INBOX.Drafts, Draft
- 已发送: Sent, Sent Messages, INBOX.Sent
- 垃圾箱: Trash, Deleted, INBOX.Trash
- 垃圾邮件: Junk, Spam, INBOX.Junk, INBOX.Spam, Bulk
- 归档: Archive, Archives, INBOX.Archive
📁 文件夹名称处理
该技能通过移除\HasNoChildren等IMAP标志和引号来清理文件夹名称以便显示。对于带有标志的原始文件夹数据:
bash
python3 scripts/imap_utils.py list-folders --output json
JSON输出示例:
json
[
{
name: Drafts,
delimiter: /,
flags: [\\HasNoChildren, \\Drafts]
}
]
🤖 AI使用示例
解析结果时始终使用--output json:
bash
列出草稿并查找特定草稿
drafts=$(python3 scripts/imap_utils.py list-drafts --output json)
解析JSON以按主题查找草稿
发送草稿
python3 scripts/smtp_utils.py send-draft --draft-id $ID
检查垃圾邮件数量
spam=$(python3 scripts/imap_utils.py list-spam --output json)
获取文件夹元数据
folders=$(python3 scripts/imap_utils.py list-folders --output json)
✅ 测试
测试您的配置:
bash
python3 scripts/imap_utils.py list-folders
python3 scripts/imap_utils.py list --limit 5
python3 scripts/imap_utils.py list-spam
所有操作均为非交互式,适合自动化。
🚀 设置说明
bash
1. 创建技能目录
mkdir -p ~/OpenClaw-Workspace/skills/email-manager/scripts
cd ~/OpenClaw-Workspace/skills/email-manager
2. 创建config.json
cat > config.json << EOF
{
email_address: your-email@yourdomain.com,
email_password: your-password,
imap_server: mail.yourdomain.com,
imap_port: 993,
smtp_server: mail.yourdomain.com,
smtp_port: 465,
folders: {
drafts: Drafts,
sent: Sent,
trash: Trash,
junk: Junk
}
}
EOF
3. 使脚本可执行
chmod +x scripts/*.py
4. 测试!
python3 scripts/imap_utils.py list-folders
📝 常见垃圾邮件文件夹名称
不同的Dovecot配置使用不同的垃圾邮件文件夹名称:
- - Junk(最常见)
- Spam
- INBOX.Junk
- INBOX.Spam
- Bulk
- Junk E-mail
如果自动检测不起作用,请在config.json中显式设置:
json
{
folders: {
junk: INBOX.Junk
}
}
🎯 主要优势
- - ✅ 零依赖 - 仅使用Python标准库
- ✅ 无需虚拟环境 - 与系统Python一起使用
- ✅ JSON配置 - 易于编辑,无需解析库
- ✅ 非交互式 - 非常适合AI自动化
- ✅ 完整功能集 - 草稿、发送、文件夹、标记、移动、删除、垃圾邮件
- ✅ 兼容Debian/Ubuntu - 无外部管理环境错误