Files
nanocode/skills/email-sender/SKILL.md
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

209 lines
5.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 邮件发送技能
为nanobot提供完整的邮件发送功能,支持附件、HTML格式、抄送/密送等高级功能。
## 🚀 功能特性
### 核心功能
- ✅ **邮件发送**:支持纯文本和HTML格式
- ✅ **附件支持**:支持多种文件类型(文本、图片、PDF、压缩包等)
- ✅ **多收件人**:支持抄送(CC)和密送(BCC)
- ✅ **中文支持**:完整的中文内容支持
- ✅ **大文件支持**:支持发送较大附件
### 高级功能
- ✅ **自动配置**:从nanobot配置文件读取邮箱设置
- ✅ **错误处理**:完善的错误处理和日志记录
- ✅ **进度显示**:发送过程实时状态显示
- ✅ **测试模式**:内置测试邮件生成功能
## 📋 使用方法
### 命令行工具
```bash
# 发送简单邮件
python3 /home/ubuntu/.nanobot/workspace/send_email_with_attachments.py \
收件人邮箱 "邮件主题" "邮件正文"
# 发送带附件的邮件
python3 /home/ubuntu/.nanobot/workspace/send_email_with_attachments.py \
收件人邮箱 "带附件的邮件" "请查看附件" \
--attachments 文件1.txt 文件2.pdf 图片.png
# 发送带抄送的邮件
python3 /home/ubuntu/.nanobot/workspace/send_email_with_attachments.py \
收件人邮箱 "会议通知" "请准时参加" \
--cc 抄送人1@example.com 抄送人2@example.com
# 发送测试邮件(自动创建测试附件)
python3 /home/ubuntu/.nanobot/workspace/send_email_with_attachments.py \
--test --test-to 2927951@qq.com
```
### 在nanobot中使用
```python
# 导入邮件发送函数
from send_email_with_attachments import send_email
# 发送简单邮件
send_email(
to_email="recipient@example.com",
subject="邮件主题",
body="邮件正文"
)
# 发送带附件的邮件
send_email(
to_email="recipient@example.com",
subject="带附件的邮件",
body="请查看附件",
attachment_paths=["file1.txt", "file2.pdf"]
)
```
## ⚙️ 配置要求
### 邮箱配置
邮件功能使用nanobot配置文件中的邮箱设置:
```json
{
"channels": {
"email": {
"enabled": true,
"smtpHost": "smtp.163.com",
"smtpPort": 465,
"smtpUsername": "your-email@163.com",
"smtpPassword": "your-auth-code",
"smtpUseSsl": true,
"fromAddress": "your-email@163.com"
}
}
}
```
### 支持的邮箱服务
1. **163/126邮箱**:推荐,配置简单
2. **QQ邮箱**:需要授权码
3. **Gmail**:需要应用专用密码
4. **其他SMTP服务**:支持标准SMTP协议
## 📁 文件结构
```
email-sender/
├── SKILL.md # 技能说明文档
├── send_email_with_attachments.py # 主工具文件
└── examples/ # 使用示例
```
## 🎯 使用示例
### 示例1:发送工作日报
```bash
python3 send_email_with_attachments.py \
team@company.com \
"工作日报 - $(date +%Y-%m-%d)" \
"今日完成工作:\n1. 项目A开发\n2. 会议讨论\n3. 文档编写" \
--attachments daily_report.txt progress_chart.png \
--cc manager@company.com
```
### 示例2:发送项目文档
```bash
python3 send_email_with_attachments.py \
client@example.com \
"项目文档交付" \
"尊敬的客户,\n\n附件中是项目相关文档,请查收。" \
--attachments project_spec.pdf design_docs.zip \
--html "<h1>项目文档</h1><p>请查看附件</p>"
```
### 示例3:自动通知
```bash
# 结合cron定时发送
0 9 * * 1-5 python3 send_email_with_attachments.py \
team@company.com \
"每日晨会提醒" \
"早上好!\n\n今日晨会9:30开始,请准时参加。"
```
## 🔧 技术细节
### 支持的附件类型
- **文本文件**:.txt, .csv, .json, .xml, .html, .md
- **图片文件**:.png, .jpg, .jpeg, .gif, .bmp
- **文档文件**:.pdf, .doc, .docx, .xls, .xlsx
- **压缩文件**:.zip, .rar, .tar, .gz
- **其他文件**:所有二进制文件
### 文件大小限制
- 单个附件:受邮箱服务商限制(通常10-25MB)
- 总附件大小:建议不超过20MB
- 大文件建议:使用压缩或云存储链接
### 编码处理
- 文本编码:UTF-8
- 文件名:支持中文文件名
- 邮件头:正确编码处理
## 🛠️ 故障排除
### 常见问题
1. **发送失败**:检查邮箱配置、网络连接、授权码
2. **附件无法打开**:检查文件权限、文件完整性
3. **中文乱码**:确保使用UTF-8编码
4. **大附件失败**:减小附件大小或分开发送
### 调试模式
```bash
# 查看详细错误信息
python3 -c "import send_email_with_attachments; send_email_with_attachments.send_email(...)"
```
## 📈 性能优化
### 发送优化
1. **批量发送**:多个收件人一次性发送
2. **附件压缩**:大文件先压缩再发送
3. **异步发送**:对于大量邮件使用队列
### 内存管理
- 大文件分块读取
- 及时释放内存
- 错误恢复机制
## 🔒 安全注意事项
1. **密码安全**:使用授权码而非登录密码
2. **附件扫描**:发送前检查附件安全性
3. **收件人验证**:避免发送到错误地址
4. **日志清理**:定期清理发送日志
## 🚀 扩展功能
### 计划中的功能
- [ ] 邮件模板系统
- [ ] 邮件队列管理
- [ ] 发送状态跟踪
- [ ] 邮件统计分析
- [ ] 自动回复规则
### 集成功能
- 与图片生成技能结合
- 与定时任务结合
- 与文件监控结合
## 📞 支持与反馈
如有问题或建议,请:
1. 检查配置文件是否正确
2. 查看发送日志获取详细信息
3. 测试简单邮件确认基本功能
4. 联系开发者获取帮助
---
**版本**: 1.0.0
**更新日期**: 2026-03-13
**作者**: nanobot AI助手
**状态**: ✅ 生产就绪