OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  smtp-send: 通过 SMTP 发送包含附件的 HTML 邮件

smtp-send: 通过 SMTP 发送包含附件的 HTML 邮件

 
  middleware ·  2026-02-01 23:21:43 · 3 次点击  · 0 条评论  

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 文件中配置(可选其一或两者都配):

方式 1: Resend API(推荐,更简单)

{
    "resend_api_key": "re_xxxxx",
    "resend_from": "you@your-domain.com"
}

获取 API 密钥: https://resend.com

注意:免费账户只能发送到注册邮箱,如需发送给其他人,需验证域名。

方式 2: SMTP(163/QQ/Gmail 等)

{
    "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,若失败则降级至 SMTP
  • smtp:强制使用 SMTP 服务
  • resend:强制使用 Resend API

📧 常见 SMTP 服务器配置

邮箱服务 主机 端口 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
  • API 密钥和密码不会在命令行参数中暴露
  • 请勿将配置文件提交到版本控制系统

🐛 常见问题

认证失败:请检查授权码是否正确,并确认已开启 SMTP 服务

Resend 403 错误:免费账户只能发送到注册邮箱,如需发送给其他人,请验证域名

连接超时:请检查网络连接,或确认端口未被防火墙拦截

3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor