# email-sender > 通过 SMTP 发送邮件。支持纯文本、HTML 和附件邮件。当用户需要发送邮件、发送报告、发送通知时使用此 skill。用户需在 .env 文件中配置 SMTP 服务器信息。 - Author: alex90thu - Repository: alex90thu/skills - Version: 20260124100437 - Stars: 0 - Forks: 0 - Last Updated: 2026-02-06 - Source: https://github.com/alex90thu/skills - Web: https://mule.run/skillshub/@@alex90thu/skills~email-sender:20260124100437 --- --- name: email-sender description: 通过 SMTP 发送邮件。支持纯文本、HTML 和附件邮件。当用户需要发送邮件、发送报告、发送通知时使用此 skill。用户需在 .env 文件中配置 SMTP 服务器信息。 --- # 邮件发送 通过 SMTP 协议发送邮件,支持纯文本、HTML 格式和附件。 ## 环境配置 在 `.env` 文件中配置: ```env SMTP_SERVER=smtp.qq.com # SMTP 服务器地址 (必需) SMTP_PORT=587 # SMTP 端口 (默认: 587) SMTP_USER=your_email@qq.com # 发件人邮箱 (必需) SMTP_PASSWORD=your_auth_code # 授权码 (必需,非登录密码) SMTP_USE_SSL=false # 使用 SSL (默认: false) SMTP_SENDER_NAME=实验室通知 # 发件人显示名称 (可选) ``` ### 常用 SMTP 配置 | 邮箱服务 | 服务器 | 端口 | 加密方式 | |---------|--------|------|----------| | QQ 邮箱 | smtp.qq.com | 587 | STARTTLS | | 163 邮箱 | smtp.163.com | 465 | SSL (`SMTP_USE_SSL=true`) | | Gmail | smtp.gmail.com | 587 | STARTTLS | | Outlook | smtp.office365.com | 587 | STARTTLS | ## 快速使用 (scripts/email_client.py) ```bash # 测试 SMTP 连接 python email_client.py test # 发送纯文本邮件 python email_client.py send "recipient@example.com" "邮件主题" "邮件正文" # 发送 HTML 邮件 python email_client.py send-html "recipient@example.com" "邮件主题" template.html # 发送带附件的邮件 python email_client.py send-attach "recipient@example.com" "报告" "请查收附件" report.pdf data.xlsx ``` ## Python API ```python from email_client import send_email, send_text_email, send_html_email # 简单文本邮件 send_text_email("user@example.com", "主题", "正文内容") # HTML 邮件 send_html_email("user@example.com", "主题", "

标题

内容

") # 完整功能:多收件人、抄送、附件 send_email( to=["user1@example.com", "user2@example.com"], subject="实验报告", body="请查收本周实验报告", attachments=["report.pdf", "data.xlsx"], cc="leader@example.com", bcc="archive@example.com" ) ``` ## 注意事项 1. **授权码**: 使用邮箱的授权码而非登录密码(需在邮箱设置中开启 SMTP 服务并生成) 2. **发送限制**: 各邮箱服务商有日发送量限制,批量发送请注意频率 3. **附件大小**: 单封邮件附件总大小通常不超过 25MB