{"id":27884375,"url":"https://github.com/howiehz/webhook-email-sender","last_synced_at":"2025-05-05T06:36:46.733Z","repository":{"id":273512827,"uuid":"919961925","full_name":"HowieHz/webhook-email-sender","owner":"HowieHz","description":"一个基于 FastAPI 的高性能异步 Webhook 服务，用于通过 SMTP 发送电子邮件","archived":false,"fork":false,"pushed_at":"2025-01-21T10:53:54.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T11:30:11.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HowieHz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-21T10:19:47.000Z","updated_at":"2025-01-21T10:48:42.000Z","dependencies_parsed_at":"2025-01-21T11:30:44.533Z","dependency_job_id":"01839eb2-627b-4b30-88d7-fc0268d14f07","html_url":"https://github.com/HowieHz/webhook-email-sender","commit_stats":null,"previous_names":["howiehz/webhook-email-sender"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HowieHz%2Fwebhook-email-sender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HowieHz%2Fwebhook-email-sender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HowieHz%2Fwebhook-email-sender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HowieHz%2Fwebhook-email-sender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HowieHz","download_url":"https://codeload.github.com/HowieHz/webhook-email-sender/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252454635,"owners_count":21750505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-05T06:36:46.218Z","updated_at":"2025-05-05T06:36:46.727Z","avatar_url":"https://github.com/HowieHz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webhook Email Sender\n\n![GitHub](https://img.shields.io/github/license/HowieHz/webhook-email-sender)\n![GitHub all releases](https://img.shields.io/github/downloads/HowieHz/webhook-email-sender/total)\n![GitHub release (latest by date)](https://img.shields.io/github/downloads/HowieHz/webhook-email-sender/latest/total)\n![GitHub repo size](https://img.shields.io/github/repo-size/HowieHz/webhook-email-sender)\n\n一个基于 FastAPI 的高性能异步 Webhook 服务，用于通过 SMTP 发送电子邮件。\n\n## 功能\n\n- 接收 GET 和 POST 请求作为 Webhook 触发器\n- 发送纯文本或 HTML 格式的电子邮件\n- 配置灵活，支持多种 SMTP 服务器\n- 异步处理，提高性能和响应速度\n\n## 目录\n\n- [Webhook Email Sender](#webhook-email-sender)\n  - [功能](#功能)\n  - [目录](#目录)\n  - [部署服务](#部署服务)\n    - [从二进制文件部署](#从二进制文件部署)\n      - [先决条件](#先决条件)\n      - [下载分发的二进制文件](#下载分发的二进制文件)\n    - [从源码部署](#从源码部署)\n      - [先决条件](#先决条件-1)\n      - [安装](#安装)\n  - [配置](#配置)\n  - [运行](#运行)\n    - [从二进制文件运行](#从二进制文件运行)\n    - [从源码运行](#从源码运行)\n  - [使用](#使用)\n    - [发送 GET 请求](#发送-get-请求)\n      - [查询参数](#查询参数)\n    - [发送 POST 请求](#发送-post-请求)\n      - [JSON 参数](#json-参数)\n      - [Header 要求](#header-要求)\n  - [故障排除](#故障排除)\n\n## 部署服务\n\n你可以选择 [从二进制文件部署](#从二进制文件部署) 或 [从源码部署](#从源码部署)\n\n### 从二进制文件部署\n\n#### 先决条件\n\n- SMTP 服务器账号（如 Gmail, QQ 邮箱等）\n\n#### 下载分发的二进制文件\n\n从 [Releases](https://github.com/HowieHz/webhook-email-sender/releases) 页面下载最新二进制文件即可\n\n### 从源码部署\n\n#### 先决条件\n\n- Python 3.8+\n- SMTP 服务器账号（如 Gmail, QQ 邮箱等）\n\n#### 安装\n\n1. **克隆仓库**\n\n   ```bash\n   git clone https://github.com/HowieHz/webhook-email-sender.git\n   cd webhook-email-sender\n   ```\n\n2. **创建并激活虚拟环境**\n\n   ```bash\n   python -m venv venv\n   # Windows\n   venv\\Scripts\\activate\n   # macOS/Linux\n   source venv/bin/activate\n   ```\n\n3. **安装依赖**\n\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n## 配置\n\n编辑 config.json 文件，填写你的 SMTP 服务器信息和服务配置。\n\n```json\n{\n  \"SMTP_SERVER\": \"smtp.example.com\",\n  \"SMTP_PORT\": 587,\n  \"SMTP_TLS\": false,\n  \"SMTP_USERNAME\": \"your_username\",\n  \"SMTP_PASSWORD_ENV\": \"SMTP_PASSWORD\",\n  \"SMTP_PASSWORD\": \"your_password\",\n  \"SERVICE_HOST\": \"127.0.0.1\",\n  \"SERVICE_PORT\": 5000,\n  \"SERVICE_PATH\": \"/webhook\",\n  \"SERVICE_TOKEN\": \"\"\n}\n```\n\n- **SMTP_SERVER**: SMTP 服务器地址\n- **SMTP_PORT**: SMTP 服务器端口\n- **SMTP_TLS**: 是否启用 TLS 加密\n- **SMTP_USERNAME**: SMTP 登录用户名\n- **SMTP_PASSWORD_ENV**: 存储 SMTP 密码的环境变量名称\n- **SMTP_PASSWORD**: SMTP 登录密码（如果未设置环境变量）\n- **SERVICE_HOST**: 服务监听的主机\n- **SERVICE_PORT**: 服务监听的端口\n- **SERVICE_PATH**: Webhook 路径\n- **SERVICE_TOKEN**: 用于身份验证的令牌，如果置空则为不启用\n\n\u003e **解释**：程序会先读取配置文件 **SMTP_PASSWORD_ENV** 项所指定的环境变量，如果指定的环境变量未设置，则会读取配置文件的 **SMTP_PASSWORD**  项作为密码。\n\n\u003e **注意**: 为了安全起见，不要将 config.json 传到公共代码仓库。\n\n## 运行\n\n### 从二进制文件运行\n\n直接运行下载的二进制文件即可启动服务\n\n### 从源码运行\n\n使用以下命令启动服务：\n\n```bash\npython main.py\n```\n\n或者使用 uvicorn 直接运行：\n\n```bash\nuvicorn main:app --host 127.0.0.1 --port 5000\n```\n\n服务将监听配置文件中指定的主机和端口。\n\n## 使用\n\n### 发送 GET 请求\n\n发送带查询参数的 GET 请求以触发邮件发送。\n\n#### 查询参数\n\n- **to**: 收件人的电子邮件地址（必需）\n- **subject**: 邮件主题（可选）\n- **body**: 邮件正文内容（可选）\n- **type**: 邮件内容的类型，\"plain\" 或 \"html\"（可选，默认为 \"plain\"）\n- **token**: 用于身份验证的令牌（如启用则为必需项）\n\n\n**示例**：\n\n```powershell\nInvoke-WebRequest -Uri \"http://localhost:5000/webhook?subject=测试邮件\u0026to=recipient@example.com\u0026body=这是测试邮件内容\" -Method GET\n```\n\n```bash\ncurl \"http://localhost:5000/webhook?subject=测试邮件\u0026to=recipient@example.com\u0026body=这是测试邮件内容\"\n```\n\n### 发送 POST 请求\n\n发送 JSON 数据的 POST 请求以触发邮件发送。\n\n#### JSON 参数\n\n- **to**: 收件人的电子邮件地址（必需）\n- **subject**: 邮件主题（可选）\n- **body**: 邮件正文内容（可选）\n- **type**: 邮件内容的类型，\"plain\" 或 \"html\"（可选，默认为 \"plain\"）\n- **token**: 用于身份验证的令牌（如启用则为必需项）\n\n#### Header 要求\n\n- **Content-Type**: 必须包括 `application/json`\n\n**PowerShell 示例**：\n\n```powershell\n$headers = @{\n    \"Content-Type\" = \"application/json; charset=utf-8\"\n}\n\n$body = @{\n    subject = \"测试邮件\"\n    body    = \"这是测试邮件内容\"\n    to      = \"recipient@example.com\"\n    type    = \"plain\"\n} | ConvertTo-Json\n\nInvoke-RestMethod -Uri \"http://localhost:5000/webhook\" `\n    -Method POST `\n    -Headers $headers `\n    -Body $body\n```\n\n**cURL 示例**：\n\n```bash\ncurl -X POST \"http://localhost:5000/webhook\" \\\n     -H \"Content-Type: application/json; charset=utf-8\" \\\n     -d '{\"subject\": \"测试邮件\", \"body\": \"这是测试邮件内容\", \"to\": \"recipient@example.com\", \"type\": \"plain\"}'\n```\n\n## 故障排除\n\n- **配置文件未找到**: 确保 config.json 存在于项目根目录，并且包含所有必需的字段。\n- **SMTP 连接失败**: 检查 SMTP 服务器地址、端口、用户名和密码是否正确。确保网络允许与 SMTP 服务器的连接。\n- **邮件发送失败**: 查看服务器日志中的错误信息，确保 SMTP 配置正确，并且目标邮箱地址有效。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowiehz%2Fwebhook-email-sender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhowiehz%2Fwebhook-email-sender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowiehz%2Fwebhook-email-sender/lists"}