feat: add user send mail client

This commit is contained in:
dreamhunter2333
2026-08-23 17:44:21 +08:00
parent dccca92928
commit 43d9a9dfe9
18 changed files with 728 additions and 23 deletions
@@ -2,12 +2,13 @@
## 通过 HTTP API 发送邮件
种 HTTP API 端点可以发送邮件,区别如下:
种 HTTP API 端点可以发送邮件,区别如下:
| 端点 | 认证方式 | 适用场景 |
|------|---------|---------|
| `/api/send_mail` | `Authorization: Bearer <地址JWT>` header | 内部调用,需要先通过 cookie / header 鉴权 |
| `/external/api/send_mail` | 请求体中的 `token` 字段 | 外部系统集成,无需 header 鉴权 |
| `/user_api/address/:address_id/send_mail` | `x-user-token: <用户JWT>` header | 已登录用户使用自己的绑定邮箱发信 |
::: tip 什么是"地址 JWT"
地址 JWT 是通过 `/api/new_address``/admin/new_address` 创建邮箱地址时返回的 `jwt` 字段。
@@ -59,6 +60,41 @@ res = requests.post(
)
```
### 方式三:使用用户 JWT`/user_api/address/:address_id/send_mail`
`address_id` 可从分页接口 `GET /user_api/bind_address` 的结果中获取。后端会验证该地址属于当前用户,客户端不能自行指定发件邮箱。
```python
send_body = {
"from_name": "发件人名字",
"to_name": "收件人名字",
"to_mail": "收件人地址",
"subject": "邮件主题",
"is_html": False,
"content": "邮件内容",
}
res = requests.post(
"https://你的worker域名/user_api/address/123/send_mail",
json=send_body,
headers={
"x-user-token": "<用户JWT>",
"Content-Type": "application/json",
},
)
```
同一组用户地址接口还包括:
| 方法 | 端点 | 说明 |
| --- | --- | --- |
| `GET` | `/user_api/address/:address_id/settings` | 获取地址和剩余发信额度 |
| `POST` | `/user_api/address/:address_id/request_send_mail_access` | 为该地址申请发信权限 |
| `GET` | `/user_api/address/:address_id/sendbox?limit=20&offset=0` | 分页获取该地址的发件箱 |
| `DELETE` | `/user_api/address/:address_id/sendbox/:mail_id` | 删除该地址的一条发件记录 |
以上接口都只接受用户 JWT,并在执行操作前验证 `address_id` 是否绑定到当前用户。
## 通过 SMTP 发送邮件
请先参考 [配置 SMTP 代理](/zh/guide/feature/config-smtp-proxy.html)。