名称: zoho-email-integration
描述: 完整的 Zoho Mail 集成,支持 OAuth2、REST API(速度提升 5-10 倍)、Clawdbot 的 /email 命令、HTML 邮件、附件和批量操作。已针对路径遍历和命令注入进行安全加固。适用于邮件自动化和工作流。
主页: https://github.com/briansmith80/clawdbot-zoho-email
元数据:
openclaw:
requires:
bins:
- python3
env:
- ZOHO_EMAIL
- ZOHO_PASSWORD
primaryEnv: ZOHO_EMAIL
tokenFile: "~/.clawdbot/zoho-mail-tokens.json"
v2.2.6 - 完整的 Zoho Mail 集成,支持 OAuth2 认证、REST API 后端(比 IMAP/SMTP 快 5-10 倍)以及用于 Telegram/Discord 的 Clawdbot 扩展 /email 命令。已针对路径遍历和命令注入进行安全加固。支持 HTML 邮件、附件、批量操作和高级自动化工作流。
选择认证方式:OAuth2(推荐,安全)或应用密码(设置简单)。
clawhub install zoho-email-integration --force
或更新所有技能:
clawhub update
关键修复: 移除了易受攻击的 JavaScript 命令处理器。如果您从示例文件夹部署了 email-command.js,请立即更新:
# 重新下载安全的处理器
clawhub install zoho-email-integration --force
cp ~/.openclaw/skills/zoho-email-integration/examples/clawdbot-extension/email-command.js /your/deployment/path/
易受攻击的版本使用了带有 shell 插值的 execSync。新版本使用带有参数数组的 spawn 来防止命令注入。
clawdhub install zoho-email
要求:
- Python 3.x
- requests 库(安装:pip3 install requests)
- Zoho Mail 账户
重要: 不要使用您的主 Zoho 密码!
选项 A:环境变量
导出您的 Zoho 凭据:
export ZOHO_EMAIL="your-email@domain.com"
export ZOHO_PASSWORD="your-app-specific-password"
选项 B:凭据文件
创建 ~/.clawdbot/zoho-credentials.sh:
#!/bin/bash
export ZOHO_EMAIL="your-email@domain.com"
export ZOHO_PASSWORD="your-app-specific-password"
使其可执行并确保安全:
chmod 600 ~/.clawdbot/zoho-credentials.sh
然后在运行前加载它:
source ~/.clawdbot/zoho-credentials.sh
python3 scripts/zoho-email.py unread
预期输出:
{"unread_count": 5}
所有命令都需要通过环境变量设置凭据。
# 诊断设置(推荐第一步)
python3 scripts/zoho-email.py doctor
# 未读邮件计数(适合简报)
python3 scripts/zoho-email.py unread
# 搜索收件箱
python3 scripts/zoho-email.py search "invoice"
# 获取特定邮件(文件夹 + ID)
python3 scripts/zoho-email.py get INBOX <id>
# 发送简单邮件
python3 scripts/zoho-email.py send recipient@example.com "Subject" "Body text"
# 清空垃圾邮件(默认安全:试运行)
python3 scripts/zoho-email.py empty-spam
# 实际执行
python3 scripts/zoho-email.py empty-spam --execute
# 清空回收站(默认安全:试运行)
python3 scripts/zoho-email.py empty-trash
# 实际执行
python3 scripts/zoho-email.py empty-trash --execute
发送格式丰富的 HTML 邮件,支持 multipart/alternative(同时包含 HTML 和纯文本版本):
CLI 命令:
# 从文件发送 HTML
python3 scripts/zoho-email.py send-html recipient@example.com "Newsletter" examples/templates/newsletter.html
# 从内联文本发送 HTML
python3 scripts/zoho-email.py send-html recipient@example.com "Welcome" "<h1>Hello!</h1><p>Welcome to our service.</p>"
# 发送前预览 HTML 邮件
python3 scripts/zoho-email.py preview-html examples/templates/newsletter.html
Python API:
from scripts.zoho_email import ZohoEmail
zoho = ZohoEmail()
# 方法 1:发送 HTML,自动生成纯文本回退版本
zoho.send_html_email(
to="recipient@example.com",
subject="Newsletter",
html_body="<h1>Hello!</h1><p>Welcome!</p>"
)
# 方法 2:发送 HTML,附带自定义纯文本版本
zoho.send_email(
to="recipient@example.com",
subject="Newsletter",
body="Plain text version of your email",
html_body="<h1>Hello!</h1><p>HTML version of your email</p>"
)
# 从模板文件加载 HTML
with open('examples/templates/newsletter.html', 'r') as f:
html_content = f.read()
zoho.send_html_email(
to="recipient@example.com",
subject="Monthly Newsletter",
html_body=html_content
)
特性:
- ✅ Multipart/alternative 邮件(HTML + 纯文本)
- ✅ 自动生成的纯文本回退版本
- ✅ 从文件或内联字符串加载 HTML
- ✅ 预览模式,可在发送前测试
- ✅ 完整的 CSS 样式支持
- ✅ 兼容所有邮件客户端
模板:
预构建模板位于 examples/templates/:
- newsletter.html - 专业的新闻稿布局
- announcement.html - 带有横幅的重要公告
- welcome.html - 新用户欢迎邮件
- simple.html - 用于快速自定义的基础 HTML 模板
python3 scripts/zoho-email.py unread
非常适合晨间简报或通知系统。
python3 scripts/zoho-email.py search "invoice"
返回最近 10 封匹配的邮件,包含主题、发件人、日期和正文预览。
python3 scripts/zoho-email.py search-sent "client name"
返回最近 5 封匹配的已发送邮件。
python3 scripts/zoho-email.py get Inbox 4590
python3 scripts/zoho-email.py get Sent 1234
返回完整的邮件内容,包括完整的正文。
python3 scripts/zoho-email.py send "client@example.com" "Subject" "Email body here"
python3 scripts/zoho-email.py send "client@example.com" "Invoice" "Please find the invoice attached" --attach invoice.pdf --attach receipt.jpg
支持使用 --attach 标志添加多个附件。
python3 scripts/zoho-email.py list-attachments Inbox 4590
返回包含附件详情的 JSON:
[
{
"index": 0,
"filename": "invoice.pdf",
"content_type": "application/pdf",
"size": 52341
},
{
"index": 1,
"filename": "receipt.jpg",
"content_type": "image/jpeg",
"size": 128973
}
]
# 下载第一个附件(索引 0),使用原始文件名
python3 scripts/zoho-email.py download-attachment Inbox 4590 0
# 下载第二个附件(索引 1),使用自定义文件名
python3 scripts/zoho-email.py download-attachment Inbox 4590 1 my-receipt.jpg
返回包含下载详情的 JSON:
{
"filename": "invoice.pdf",
"output_path": "invoice.pdf",
"size": 52341,
"content_type": "application/pdf"
}
检查未读邮件并报告:
UNREAD=$(python3 scripts/zoho-email.py unread | jq -r '.unread_count')
echo "📧 You have $UNREAD unread emails"
监控 VIP 邮件:
RESULTS=$(python3 scripts/zoho-email.py search "Important Client")
COUNT=$(echo "$RESULTS" | jq '. | length')
if [ $COUNT -gt 0 ]; then
echo "⚠️ New email from Important Client!"
fi
搜索和回复工作流:
# 查找最新的发票查询
EMAIL=$(python3 scripts/zoho-email.py search "invoice" | jq -r '.[0]')
FROM=$(echo "$EMAIL" | jq -r '.from')
# 发送回复
python3 scripts/zoho-email.py send "$FROM" "Re: Invoice" "Thanks for your inquiry..."
自动下载发票附件:
# 搜索发票邮件
EMAILS=$(python3 scripts/zoho-email.py search "invoice")
# 获取最新邮件 ID
EMAIL_ID=$(echo "$EMAILS" | jq -r '.[0].id')
# 列出附件
ATTACHMENTS=$(python3 scripts/zoho-email.py list-attachments Inbox "$EMAIL_ID")
# 下载所有 PDF 附件
echo "$ATTACHMENTS" | jq -r '.[] | select(.content_type == "application/pdf") | .index' | while read INDEX; do
python3 scripts/zoho-email.py download-attachment Inbox "$EMAIL_ID" "$INDEX" "invoice_${INDEX}.pdf"
echo "Downloaded invoice_${INDEX}.pdf"
done
发送带附件的报告:
# 生成报告
python3 generate_report.py > report.txt
# 发送带附件的邮件
python3 scripts/zoho-email.py send "manager@example.com" "Weekly Report" "Please see attached report" --attach report.txt --attach chart.png
导入模块以进行编程使用:
from scripts.zoho_email import ZohoEmail
zoho = ZohoEmail()
# 搜索邮件
results = zoho.search_emails(folder="INBOX", query='SUBJECT "invoice"', limit=10)
# 获取特定邮件
email = zoho.get_email(folder="Sent", email_id="4590")
# 发送纯文本邮件
zoho.send_email(
to="client@example.com",
subject="Hello",
body="Message text",
cc="manager@example.com" # 可选
)
# 发送 HTML 邮件(自动生成纯文本回退版本)
zoho.send_html_email(
to="client@example.com",
subject="Newsletter",
html_body="<h1>Welcome!</h1><p>Rich HTML content here</p>",
text_body="Welcome! Plain text version here" # 可选,如未提供则自动生成
)
# 发送 multipart 邮件(HTML + 自定义纯文本)
zoho.send_email(
to="client@example.com",
subject="Update",
body="Plain text version",
html_body="<h1>HTML version</h1>",
cc="manager@example.com"
)
# 发送带附件的邮件
zoho.send_email_with_attachment(
to="client@example.com",
subject="Invoice",
body="Please find the invoice attached",
attachments=["invoice.pdf", "receipt.jpg"],
cc="manager@example.com" # 可选
)
# 列出附件
attachments = zoho.get_attachments(folder="INBOX", email_id="4590")
for att in attachments:
print(f"{att['index']}: {att['filename']} ({att['size']} bytes)")
# 下载附件
result = zoho.download_attachment(
folder="INBOX",
email_id="4590",
attachment_index=0,
output_path="downloaded_file.pdf" # 可选,如未提供则使用原始文件名
)
# 检查未读计数
count = zoho.get_unread_count()
查看 examples/send-html-newsletter.py 中的完整示例:
# 运行 HTML 邮件示例
python3 examples/send-html-newsletter.py
此示例演示:
- 发送简单的内联 HTML
- 加载和发送 HTML 模板
- 自定义纯文本回退版本
- 专业的邮件布局
快速开始:
#!/usr/bin/env python3
from scripts.zoho_email import ZohoEmail
zoho = ZohoEmail()
# 加载模板
with open('examples/templates/welcome.html', 'r') as f:
html = f.read()
# 发送给收件人
zoho.send_html_email(
to="newuser@example.com",
subject="🎉 Welcome to Our Platform!",
html_body=html
)
常见的 Zoho Mail 文件夹:
INBOX - 主收件箱Sent - 已发送邮件Drafts - 草稿邮件Spam - 垃圾邮件文件夹Trash - 已删除邮件INBOX/ClientName)覆盖默认的 IMAP/SMTP 服务器(如果使用自托管的 Zoho Mail):
export ZOHO_IMAP="imap.yourdomain.com"
export ZOHO_SMTP="smtp.yourdomain.com"
export ZOHO_IMAP_PORT="993"
export ZOHO_SMTP_PORT="465"
您忘记导出凭据了!运行:
export ZOHO_EMAIL="your-email@domain.com"
export ZOHO_PASSWORD="your-app-password"