Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📨 Seed Email — 安全邮件发送服务

基于 Resend + Vercel Edge Runtime 的轻量级邮件 API,适用于博客联系表单、通知系统等场景。
作者:xiatianxuan

License: AGPL v3


🔒 许可证

本项目采用 GNU Affero General Public License v3.0 (AGPL-3.0)
根据许可证要求,任何通过网络提供本服务的行为必须向用户提供完整源代码

源代码地址:https://github.com/xiatianxuan/seed-email

完整许可证文本见 LICENSE 文件。


🚀 功能特性

  • ✅ 支持单收件人或多人列表
  • ✅ 发送 HTML 格式邮件
  • ✅ 自定义 API 密钥认证(防未授权调用)
  • ✅ 自动标准化收件人格式
  • ✅ 运行于 Vercel Edge Runtime(低延迟)
  • ✅ 统一返回 success: true/false 响应结构

⚙️ 运行环境要求

组件 版本要求
Node.js ≥ 18.x
npm / pnpm 最新版

💡 无需数据库或其他后端依赖。


🛠 本地开发

1. 安装依赖

npm install

2. 配置环境变量

在项目根目录创建 .env.local 文件(切勿提交到 Git):

# Resend API 密钥(从 https://resend.com/dashboard 获取)
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxxx

# 自定义调用密钥(由你设定)
SEED_SEND_API_KEY=your_strong_secret_key_here

# 发件人邮箱(必须已在 Resend 验证)
FROM_EMAIL=youremail@email.com

3. 启动服务

npm run dev

服务运行于 http://localhost:3000

4. 测试接口

curl -X POST http://localhost:3000/api/email \
  -H "Content-Type: application/json" \
  -d '{
    "SEED_SEND_API_KEY": "your_strong_secret_key_here",
    "to": "test@example.com",
    "subject": "测试邮件",
    "html": "<h1>Hello from Seed Email!</h1>"
  }'

📥 API 调用说明

Endpoint

POST /api/email/send
Content-Type: application/json

请求体参数

字段 类型 必填 说明
SEED_SEND_API_KEY string 你的自定义密钥
to string 或 string[] 收件人邮箱(非空)
subject string 邮件主题(非空)
html string HTML 内容(字段必须存在,值可为空字符串)

成功响应

{
  "success": true,
  "id": "67890abcdef...",
  "object": "email"
}

错误响应示例

{
  "success": false,
  "error": "Unauthorized"
}

常见错误:

  • Invalid JSON.:请求体不是合法 JSON
  • UnauthorizedSEED_SEND_API_KEY 缺失或错误
  • Missing fields...:缺少必填字段

🛡 安全建议

  • 严禁将 SEED_SEND_API_KEY 暴露在前端代码中
  • 建议在生产环境增加速率限制(如 Upstash Redis)
  • 确保 FROM_EMAIL 域名已在 Resend 完成 DNS 验证

© 2026 xiatianxuan
This program comes with ABSOLUTELY NO WARRANTY.
See LICENSE for details.


About

A api to send email from CodeSeed.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages