Email 📧
Email management and automation with attachment support.
Features
- - Send emails with attachments
- Support for multiple email providers (Gmail, Outlook, Yahoo, etc.)
- HTML and plain text email support
- CC and BCC recipients
- Test email functionality
- Secure TLS/SSL connections
Setup Instructions
1. Configure Email Credentials
Create a configuration file email_config.json in your workspace:
CODEBLOCK0
2. For Gmail Users (Recommended)
- 1. Enable 2-factor authentication on your Google account
- Generate an App Password:
- Go to https://myaccount.google.com/security
- Under "Signing in to Google," select "App passwords"
- Generate a new app password for "Mail"
- Use this 16-character password in your config
3. Alternative: Environment Variables
Set these environment variables instead of using a config file:
CODEBLOCK1
Usage Examples
Send a Simple Email
CODEBLOCK2
Send Email with Attachment
CODEBLOCK3
Send Test Email
CODEBLOCK4
Using with OpenClaw Commands
CODEBLOCK5
Supported Email Providers
| Provider | SMTP Server | Port | TLS |
|---|
| Gmail | smtp.gmail.com | 587 | Yes |
| Outlook/Office365 |
smtp.office365.com | 587 | Yes |
| Yahoo | smtp.mail.yahoo.com | 587 | Yes |
| QQ Mail | smtp.qq.com | 587 | Yes |
| Custom SMTP | your.smtp.server.com | 587/465 | As configured |
Python API Usage
CODEBLOCK6
Troubleshooting
Common Issues:
- 1. Authentication Failed
- Verify your username and password
- For Gmail: Use app password instead of regular password
- Check if 2FA is enabled
- 2. Connection Refused
- Verify SMTP server and port
- Check firewall settings
- Try different port (465 for SSL)
- 3. Attachment Too Large
- Most providers limit attachments to 25MB
- Consider compressing files or using cloud storage links
Security Notes
- - Never commit email credentials to version control
- Use environment variables for production deployments
- Regularly rotate app passwords
- Consider using dedicated email accounts for automation
电子邮件 📧
支持附件的电子邮件管理与自动化功能。
功能特性
- - 发送带附件的电子邮件
- 支持多种邮件服务商(Gmail、Outlook、Yahoo等)
- 支持HTML和纯文本格式邮件
- 支持抄送和密送收件人
- 测试邮件功能
- 安全的TLS/SSL连接
配置说明
1. 配置邮件凭证
在工作目录下创建配置文件 email_config.json:
json
{
smtp_server: smtp.gmail.com,
smtp_port: 587,
username: your-email@gmail.com,
password: your-app-password,
sender_name: OpenClaw Assistant,
use_tls: true,
use_ssl: false
}
2. Gmail用户配置(推荐)
- 1. 在Google账户中启用两步验证
- 生成应用专用密码:
- 访问 https://myaccount.google.com/security
- 在登录Google部分选择应用密码
- 为邮件生成新的应用密码
- 在配置中使用这个16位密码
3. 替代方案:环境变量
使用环境变量替代配置文件:
bash
Windows系统
set SMTP_SERVER=smtp.gmail.com
set SMTP_PORT=587
set EMAIL_USERNAME=your-email@gmail.com
set EMAIL_PASSWORD=your-app-password
set EMAIL
SENDERNAME=OpenClaw Assistant
macOS/Linux系统
export SMTP_SERVER=smtp.gmail.com
export SMTP_PORT=587
export EMAIL_USERNAME=your-email@gmail.com
export EMAIL_PASSWORD=your-app-password
export EMAIL
SENDERNAME=OpenClaw Assistant
使用示例
发送简单邮件
bash
python email_sender.py --to recipient@example.com --subject 你好 --body 这是一封测试邮件
发送带附件的邮件
bash
python email_sender.py --to recipient@example.com --subject 报告 --body 请查收附件 --attachment report.pdf --attachment data.xlsx
发送测试邮件
bash
python email_sender.py --to your-email@gmail.com --test
配合OpenClaw命令使用
发送邮件至 recipient@example.com,主题为会议纪要,内容为这是今天会议的记录
发送测试邮件以验证配置
将 report.pdf 文件通过邮件发送至 team@company.com
支持的邮件服务商
| 服务商 | SMTP服务器 | 端口 | TLS |
|---|
| Gmail | smtp.gmail.com | 587 | 是 |
| Outlook/Office365 |
smtp.office365.com | 587 | 是 |
| Yahoo | smtp.mail.yahoo.com | 587 | 是 |
| QQ邮箱 | smtp.qq.com | 587 | 是 |
| 自定义SMTP | your.smtp.server.com | 587/465 | 按配置 |
Python API使用
python
from email_sender import EmailSender
使用配置文件初始化
sender = EmailSender(email_config.json)
发送带附件的邮件
result = sender.send_email(
to_email=recipient@example.com,
subject=重要文件,
body=请审阅附件中的文件。,
attachments=[document.pdf, data.csv]
)
if result[success]:
print(f邮件已发送,包含 {result[attachments]} 个附件)
else:
print(f错误:{result[error]})
故障排除
常见问题:
- 1. 认证失败
- 验证用户名和密码是否正确
- Gmail用户:使用应用密码而非常规密码
- 检查是否已启用两步验证
- 2. 连接被拒绝
- 验证SMTP服务器和端口是否正确
- 检查防火墙设置
- 尝试其他端口(SSL使用465端口)
- 3. 附件过大
- 大多数服务商限制附件大小为25MB
- 考虑压缩文件或使用云存储链接
安全注意事项
- - 切勿将邮件凭证提交到版本控制系统
- 生产环境部署时使用环境变量
- 定期轮换应用密码
- 建议使用专用邮箱账户进行自动化操作