基于 Resend + Vercel Edge Runtime 的轻量级邮件 API,适用于博客联系表单、通知系统等场景。
作者:xiatianxuan
本项目采用 GNU Affero General Public License v3.0 (AGPL-3.0)。
根据许可证要求,任何通过网络提供本服务的行为必须向用户提供完整源代码。
完整许可证文本见 LICENSE 文件。
- ✅ 支持单收件人或多人列表
- ✅ 发送 HTML 格式邮件
- ✅ 自定义 API 密钥认证(防未授权调用)
- ✅ 自动标准化收件人格式
- ✅ 运行于 Vercel Edge Runtime(低延迟)
- ✅ 统一返回
success: true/false响应结构
| 组件 | 版本要求 |
|---|---|
| Node.js | ≥ 18.x |
| npm / pnpm | 最新版 |
💡 无需数据库或其他后端依赖。
npm install在项目根目录创建 .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.comnpm run dev服务运行于 http://localhost:3000
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>"
}'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.:请求体不是合法 JSONUnauthorized:SEED_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.