docs: improve README for MailOne usage and deployment

This commit is contained in:
zimk
2026-02-26 09:46:01 +08:00
parent 93dfbc1e61
commit 2fffc85720

View File

@@ -1,50 +1,90 @@
# MailOne
MailOne 是一个基于 Cloudflare Email Worker + D1临时邮箱 API
MailOne 是一个基于 **Cloudflare Email Worker + D1** 的极简临时邮箱 API
- Catch-all 收件
- `/?to=<email>` 直接返回该收件箱最近一封邮件
- 同一收件箱只保留最新一封
- 邮件仅保留 24 小时
核心规则:
- 域名启用 Catch-all任意收件地址都可接收
- API 仅返回目标邮箱**最近一封**邮件
- 同一邮箱只保留 1 条记录(新邮件覆盖旧邮件)
- 邮件保留 24 小时(超时视为无邮件)
---
## API
```bash
GET https://<your-worker>.workers.dev/?to=test@your-domain.com
```http
GET /?to=test@your-domain.com
```
返回
示例
```bash
curl "https://xxx.zimk.workers.dev/?to=test@your-domain.com"
```
返回示例:
```json
{
"id": "...",
"id": "<message-id-or-uuid>",
"recipient": "test@your-domain.com",
"sender": "sender@example.com",
"nexthop": "your-domain.com",
"subject": "Hello",
"content": "raw email content",
"content": "<raw email content>",
"received_at": 1760000000000
}
```
无邮件或已过期>24h返回 `null`
无邮件或邮件已过期时返回:
## Deploy
```json
null
```
1. 创建 D1 数据库并把 `database_id` 写入 `wrangler.toml`
2. 执行建表:
```bash
wrangler d1 execute mailone --file=./schema.sql
```
3. 部署:
```bash
wrangler deploy
```
4. Cloudflare Email Routing 设置 catch-all -> 该 Worker
---
## Notes
## 项目结构
- 已移除 API key 鉴权(按需求)
- 清理策略:
- 读取时超过 24h 直接视为无数据
- 每小时 cron 清理数据库中的过期记录
```text
MailOne/
├─ src/index.js # Worker 逻辑fetch + email + scheduled
├─ schema.sql # D1 表结构
└─ wrangler.toml # Worker + D1 + cron 配置
```
---
## 部署步骤
1. 创建 D1 数据库
2.`wrangler.toml` 填入真实 `database_id`
3. 执行建表
```bash
wrangler d1 execute mailone --file=./schema.sql
```
4. 部署 Worker
```bash
wrangler deploy
```
5. Cloudflare Dashboard → Email Routing
- 开启 Email Routing
- 将域名的 Catch-all 路由到本 Worker
---
## 数据策略
- 每封新邮件到达时,对同一 `recipient` 执行 UPSERT覆盖
- 定时任务每小时执行一次,清理超过 24 小时的数据
- API 读取时也会做 24 小时有效期判断
---
## 注意事项
- 本项目默认**不启用 API Key 鉴权**(按需求)
- `content` 为原始邮件内容raw如需只返回正文可在后续版本增加解析逻辑