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