name: smtp-send
description: 通过 SMTP 或 Resend API 发送电子邮件,支持纯文本、HTML 和附件。当用户要求发送邮件、给某人发邮件或撰写并发送消息时使用。支持单个收件人,并可包含文件附件。兼容 Gmail、Outlook、Yahoo、QQ 邮箱、163 邮箱、Resend 及任何 SMTP 服务器。
通过 SMTP 或 Resend API 发送电子邮件。
# 发送简单邮件
python3 scripts/send_email.py \
--to recipient@example.com \
--subject "明日会议" \
--body "你好,我们明天下午2点见面。"
# 发送 HTML 邮件
python3 scripts/send_email.py \
--to recipient@example.com \
--subject "周报" \
--body "<h1>报告</h1><p>以下是更新内容...</p>" \
--html
# 发送带附件的邮件
python3 scripts/send_email.py \
--to recipient@example.com \
--subject "文件" \
--body "请查收附件。" \
--attachments report.pdf,data.csv
# 指定使用 Resend
python3 scripts/send_email.py \
--to recipient@example.com \
--subject "测试" \
--body "你好" \
--provider resend
在 ~/.smtp_config 文件中配置(可选其一或两者都配):
{
"resend_api_key": "re_xxxxx",
"resend_from": "you@your-domain.com"
}
获取 API 密钥: https://resend.com
注意:免费账户只能发送到注册邮箱,如需发送给其他人,需验证域名。
{
"host": "smtp.163.com",
"port": 465,
"user": "your-email@163.com",
"password": "your-auth-code",
"from": "your-email@163.com",
"use_ssl": true
}
{
"resend_api_key": "re_xxxxx",
"resend_from": "you@your-domain.com",
"host": "smtp.163.com",
"port": 465,
"user": "your-email@163.com",
"password": "your-auth-code",
"from": "your-email@163.com",
"use_ssl": true
}
配置完成后,设置文件权限:
chmod 600 ~/.smtp_config
| 参数 | 必填 | 说明 |
|---|---|---|
--to |
✅ | 收件人邮箱地址 |
--subject |
✅ | 邮件主题 |
--body |
✅ | 邮件正文内容 |
--html |
❌ | 以 HTML 格式发送邮件 |
--attachments |
❌ | 附件文件路径,多个文件用逗号分隔 |
--provider |
❌ | 邮件服务提供商:auto/smtp/resend(默认为 auto) |
auto(默认):优先使用 Resend,若失败则降级至 SMTPsmtp:强制使用 SMTP 服务resend:强制使用 Resend API| 邮箱服务 | 主机 | 端口 | SSL |
|---|---|---|---|
| 163 邮箱 | smtp.163.com | 465 | true |
| QQ 邮箱 | smtp.qq.com | 465 | true |
| Gmail | smtp.gmail.com | 587 | false |
| Outlook | smtp.office365.com | 587 | false |
注意:163 邮箱、QQ 邮箱和 Gmail 需使用授权码,而非登录密码。
~/.smtp_config 文件中,建议将文件权限设置为 600认证失败:请检查授权码是否正确,并确认已开启 SMTP 服务
Resend 403 错误:免费账户只能发送到注册邮箱,如需发送给其他人,请验证域名
连接超时:请检查网络连接,或确认端口未被防火墙拦截