用途
send-email 技能用于通过 SMTP 发送电子邮件,使用 Python 实现。当用户提出发送邮件、给某人发邮件等需求时,可通过该技能完成从信息收集、服务商识别、内容处理到确认发送的完整流程。
主要能力
- 支持纯文本与 HTML 格式邮件,默认纯文本。
- 自动 Markdown 转 HTML:脚本会检测内容中的标题(#、##、###)、粗体/斜体(bold、italic)、列表(- item 或 1. item)、代码块(```)、链接(text)等常见模式;若检出 Markdown,自动转换为带样式 HTML,包含排版与间距、标题配色、表格与代码块样式、适配邮件客户端的响应式设计,无需手动指定 --content-type html。
- 文件附件:可附加多个文件(--attach,可多次指定)。
- 邮件模板:使用模板文件配合变量替换(--template 与 --template-vars)。
- 多邮箱服务商支持:Gmail、Outlook/Office 365、QQ 邮箱、163/126 网易邮箱、SendGrid、Mailgun 以及自定义 SMTP。
- 默认发件人:用户未指定发件人邮箱时,自动使用 agent_skill_test@126.com,不询问发件邮箱;仅当用户明确表示要使用自己的邮箱时才询问其他发件地址。
- 自定义发件人显示名(--from-name)。
- TLS 与 SSL 加密连接(通过端口选择,或加 --use-ssl)。
使用方式
技能按交互流程引导发送:
- 收集基本信息:收件人(--to)、主题(--subject)、内容(--content)。缺失时提示用户补充。未指定发件人则默认 agent_skill_test@126.com,并进入下一步索要授权码。
- 识别邮箱服务商并收集凭据:根据发件人域名判断服务商,索取对应凭据。
- 自动检测并处理 Markdown 内容。
- 收集可选信息:--from-name、--content-type html、--attach、--template、--template-vars。
- 发送前确认发件人、收件人、主题、内容类型与附件,确认后执行 send_email.py 脚本。
脚本命令参考:
基本命令:
python3 scripts/send_email.py
--to recipient@example.com
--subject "Email Subject"
--content "Email body content"
--smtp-server smtp.gmail.com
--smtp-port 587
--username your@email.com
--password your-password-or-app-password
HTML 邮件:
python3 scripts/send_email.py
--to recipient@example.com
--subject "Email Subject"
--content "<h1>Hello</h1><p>HTML content</p>"
--content-type html
--smtp-server smtp.gmail.com
--smtp-port 587
--username your@email.com
--password your-password
带附件邮件:
python3 scripts/send_email.py
--to recipient@example.com
--subject "Email Subject"
--content "Email body"
--attach /path/to/file1.pdf
--attach /path/to/file2.csv
--smtp-server smtp.gmail.com
--smtp-port 587
--username your@email.com
--password your-password
模板邮件:
python3 scripts/send_email.py
--to recipient@example.com
--subject "Email Subject"
--template assets/simple-notification.html
--template-vars '{"title":"Notification","message":"Your report is ready!"}'
--content-type html
--smtp-server smtp.gmail.com
--smtp-port 587
--username your@email.com
--password your-password
SSL 连接(替代 TLS):
python3 scripts/send_email.py
--to recipient@example.com
--subject "Email Subject"
--content "Email body"
--smtp-server smtp.gmail.com
--smtp-port 465
--use-ssl
--username your@email.com
--password your-password
邮箱服务商配置
服务商识别规则:
- @gmail.com、@googlemail.com → Gmail
- @outlook.com、@hotmail.com、@live.com、@office365.com → Outlook/Office 365
- @qq.com、@vip.qq.com → QQ 邮箱
- @163.com、@126.com → 网易邮箱
- @aliyun.com、@aliyun-inc.com → 阿里云邮箱
- @sendgrid.net、@*.sendgrid.net → SendGrid
- @*.mailgun.org → Mailgun
- 其他域名 → 自定义 SMTP(需提供服务器、端口、用户名、密码)
各服务商凭据要求:
- Gmail:需应用专用密码(非账号密码),须先启用双重验证;获取地址 https://myaccount.google.com/apppasswords,选择 Mail 与 Other(自定义名称),生成后复制 16 位密码。SMTP:smtp.gmail.com,端口 587(TLS)或 465(SSL),用户名为完整 Gmail 地址。
- Outlook/Office 365:使用账号密码(与网页登录相同)。SMTP:smtp.office365.com,端口 587(TLS)。
- QQ 邮箱:需 SMTP 授权码(非账号密码)。登录 https://mail.qq.com,设置 → 账户,找到 POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV 服务,开启 POP3/SMTP 或 IMAP/SMTP 服务,生成授权码并短信验证后复制。SMTP:smtp.qq.com,端口 587(TLS)或 465(SSL)。
- 163 邮箱:需 SMTP 授权码。登录 https://mail.163.com,设置 → POP3/SMTP/IMAP,开启 IMAP/SMTP 服务,验证后获取 16 位授权码。SMTP:smtp.163.com,端口 465(SSL)或 994(IMAP)。
- 126 邮箱:需 SMTP 授权码。登录 https://mail.126.com,设置 → POP3/SMTP/IMAP,启用 IMAP/SMTP 服务,复制显示的授权密码。SMTP:smtp.126.com,端口 465(SSL)或 25(SSL)。
- SendGrid:使用 API Key 作为密码。登录 https://app.sendgrid.com,Settings → API Keys,创建 API Key 并复制(仅显示一次)。SMTP:smtp.sendgrid.net,端口 587(TLS)或 465(SSL),用户名固定为 apikey。
- Mailgun:使用仪表板提供的 SMTP 凭据。登录 https://app.mailgun.com,Sending → Domains,选择域名并复制 SMTP 用户名与密码。SMTP:smtp.mailgun.org,端口 587(TLS)。
- 自定义 SMTP:需提供 SMTP 服务器地址、端口、用户名、密码。
适用场景
- 向指定收件人发送通知、报告类邮件。
- 需要用 Markdown 编写内容并自动转成美观 HTML 的报告邮件。
- 需要附带 PDF、CSV 等多个文件的邮件。
- 使用固定模板进行变量替换的批量或重复性通知邮件。
- 在 Gmail、Outlook、QQ、163/126、SendGrid、Mailgun 或自建 SMTP 环境下发送邮件。
安装与资源
使用前安装 Python 依赖: pip install -r requirements.txt
这会安装 markdown 库(版本 ≥3.4.0),用于自动 Markdown 转 HTML。
资源文件:
- scripts/send_email.py:主脚本,支持纯文本与 HTML 内容、多附件、带变量替换的模板、TLS 与 SSL 加密、自定义发件人名称。
- references/smtp-servers.md:常见 SMTP 服务器配置,含 Gmail、Outlook、126、QQ、163、SendGrid、Mailgun 与阿里云。
- assets/:邮件模板,包含 simple-notification.html(基础通知模板)与 report-summary.html(带指标网格的专业报告模板)。
限制
发送前需按提示收集收件人、主题、内容等信息,并提供对应服务商的凭据;各服务商对密码类型有特定要求(如应用专用密码、授权码、API Key 等)。关于价格、收费、发送限额或具体效果,资料暂未提供。