mails 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +146 -0
- package/README.md +196 -148
- package/README.zh.md +160 -0
- package/dist/cli.js +668 -0
- package/dist/index.js +411 -0
- package/package.json +39 -26
- package/skill.md +213 -0
- package/.npmignore +0 -7
- package/LICENSE +0 -19
- package/README.en.md +0 -106
- package/bin/cli +0 -3
- package/index.js +0 -6
- package/libs/cli.js +0 -58
- package/libs/mail.js +0 -25
- package/libs/render.js +0 -13
- package/libs/serve.js +0 -59
package/README.ja.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# mails
|
|
2
|
+
|
|
3
|
+
AIエージェント向けのメールインフラ。プログラムでメールの送受信ができます。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mails)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
[English](README.md) | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## テストカバレッジ
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
全ファイル: 100.00% Functions | 100.00% Lines
|
|
14
|
+
ユニットテスト 78件 + ライブ E2E テスト 8件(実際の Resend + Cloudflare Email Routing)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 特徴
|
|
18
|
+
|
|
19
|
+
- **メール送信** — Resend経由(他のプロバイダーも追加予定)
|
|
20
|
+
- **メール受信** — Cloudflare Email Routing Worker経由
|
|
21
|
+
- **認証コード自動抽出** — メールから認証コードを自動検出(英語/中国語/日本語/韓国語対応)
|
|
22
|
+
- **ストレージプロバイダー** — ローカルSQLite(デフォルト)または [db9.ai](https://db9.ai) クラウドPostgreSQL
|
|
23
|
+
- **依存関係ゼロ** — Resendプロバイダーは `fetch()` を直接使用、SDKは不要
|
|
24
|
+
- **エージェントファースト** — `skill.md` 統合ガイド付きのAIエージェント向け設計
|
|
25
|
+
- **クラウドサービス** — `@mails.dev` アドレス、x402マイクロペイメント対応(近日公開)
|
|
26
|
+
|
|
27
|
+
## インストール
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g mails
|
|
31
|
+
# または
|
|
32
|
+
bun install -g mails
|
|
33
|
+
# または直接実行
|
|
34
|
+
npx mails
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## クイックスタート
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 設定
|
|
41
|
+
mails config set resend_api_key re_YOUR_KEY
|
|
42
|
+
mails config set default_from "Agent <agent@yourdomain.com>"
|
|
43
|
+
|
|
44
|
+
# メール送信
|
|
45
|
+
mails send --to user@example.com --subject "Hello" --body "World"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## CLIリファレンス
|
|
49
|
+
|
|
50
|
+
### 送信
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
mails send --to <email> --subject <subject> --body <text>
|
|
54
|
+
mails send --to <email> --subject <subject> --html "<h1>Hello</h1>"
|
|
55
|
+
mails send --from "Name <email>" --to <email> --subject <subject> --body <text>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 受信箱
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
mails inbox # 最近のメール一覧
|
|
62
|
+
mails inbox --mailbox agent@test.com # 特定メールボックス
|
|
63
|
+
mails inbox <id> # メール詳細表示
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 認証コード
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
mails code --to agent@test.com # コード待機(デフォルト30秒)
|
|
70
|
+
mails code --to agent@test.com --timeout 60 # タイムアウト指定
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
コードは標準出力に出力されるため、パイプで利用可能: `CODE=$(mails code --to agent@test.com)`
|
|
74
|
+
|
|
75
|
+
### 設定
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
mails config # 全設定表示
|
|
79
|
+
mails config set <key> <value> # 値を設定
|
|
80
|
+
mails config get <key> # 値を取得
|
|
81
|
+
mails config path # 設定ファイルのパス表示
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## SDK
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { send, getInbox, waitForCode } from 'mails'
|
|
88
|
+
|
|
89
|
+
// 送信
|
|
90
|
+
const result = await send({
|
|
91
|
+
to: 'user@example.com',
|
|
92
|
+
subject: 'Hello',
|
|
93
|
+
text: 'World',
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// 受信箱一覧
|
|
97
|
+
const emails = await getInbox('agent@yourdomain.com', { limit: 10 })
|
|
98
|
+
|
|
99
|
+
// 認証コード待機
|
|
100
|
+
const code = await waitForCode('agent@yourdomain.com', { timeout: 30 })
|
|
101
|
+
if (code) console.log(code.code) // "123456"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## メールワーカー
|
|
105
|
+
|
|
106
|
+
`worker/` ディレクトリにCloudflare Email Routing Workerが含まれています。
|
|
107
|
+
|
|
108
|
+
### セットアップ
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
cd worker
|
|
112
|
+
bun install
|
|
113
|
+
# wrangler.toml を編集 — D1データベースIDを設定
|
|
114
|
+
wrangler d1 create mails
|
|
115
|
+
wrangler d1 execute mails --file=schema.sql
|
|
116
|
+
wrangler deploy
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
その後、Cloudflare Email Routingでこのワーカーへの転送を設定します。
|
|
120
|
+
|
|
121
|
+
## ストレージプロバイダー
|
|
122
|
+
|
|
123
|
+
### SQLite(デフォルト)
|
|
124
|
+
|
|
125
|
+
`~/.mails/mails.db` のローカルデータベース。設定不要。
|
|
126
|
+
|
|
127
|
+
### db9.ai
|
|
128
|
+
|
|
129
|
+
AIエージェント向けクラウドPostgreSQL。
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
mails config set storage_provider db9
|
|
133
|
+
mails config set db9_token YOUR_TOKEN
|
|
134
|
+
mails config set db9_database_id YOUR_DB_ID
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## テスト
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
bun test # 全テスト実行
|
|
141
|
+
bun test --coverage # カバレッジレポート付き
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## ライセンス
|
|
145
|
+
|
|
146
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,148 +1,196 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
mails
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
1
|
+
# mails
|
|
2
|
+
|
|
3
|
+
Email infrastructure for AI agents. Send and receive emails programmatically.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mails)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
[日本語](README.ja.md) | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Test Coverage
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
---------------------------------|---------|---------|
|
|
14
|
+
File | % Funcs | % Lines |
|
|
15
|
+
---------------------------------|---------|---------|
|
|
16
|
+
All files | 100.00 | 100.00 |
|
|
17
|
+
src/cli/commands/help.ts | 100.00 | 100.00 |
|
|
18
|
+
src/core/config.ts | 100.00 | 100.00 |
|
|
19
|
+
src/core/send.ts | 100.00 | 100.00 |
|
|
20
|
+
src/core/types.ts | 100.00 | 100.00 |
|
|
21
|
+
src/providers/send/resend.ts | 100.00 | 100.00 |
|
|
22
|
+
src/providers/storage/db9.ts | 100.00 | 100.00 |
|
|
23
|
+
src/providers/storage/sqlite.ts | 100.00 | 100.00 |
|
|
24
|
+
worker/src/extract-code.ts | 100.00 | 100.00 |
|
|
25
|
+
---------------------------------|---------|---------|
|
|
26
|
+
|
|
27
|
+
78 unit tests + 8 live E2E tests (real Resend + Cloudflare Email Routing)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Send emails** via Resend (more providers coming)
|
|
33
|
+
- **Receive emails** via Cloudflare Email Routing Worker
|
|
34
|
+
- **Verification code extraction** — auto-extracts codes from emails (EN/ZH/JA/KO)
|
|
35
|
+
- **Storage providers** — local SQLite (default) or [db9.ai](https://db9.ai) cloud PostgreSQL
|
|
36
|
+
- **Zero dependencies** — Resend provider uses raw `fetch()`, no SDK needed
|
|
37
|
+
- **Agent-first** — designed for AI agents with `skill.md` integration guide
|
|
38
|
+
- **Cloud service** — `@mails.dev` addresses with x402 micropayments (coming soon)
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g mails
|
|
44
|
+
# or
|
|
45
|
+
bun install -g mails
|
|
46
|
+
# or use directly
|
|
47
|
+
npx mails
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Configure
|
|
54
|
+
mails config set resend_api_key re_YOUR_KEY
|
|
55
|
+
mails config set default_from "Agent <agent@yourdomain.com>"
|
|
56
|
+
|
|
57
|
+
# Send an email
|
|
58
|
+
mails send --to user@example.com --subject "Hello" --body "World"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## CLI Reference
|
|
62
|
+
|
|
63
|
+
### Send
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
mails send --to <email> --subject <subject> --body <text>
|
|
67
|
+
mails send --to <email> --subject <subject> --html "<h1>Hello</h1>"
|
|
68
|
+
mails send --from "Name <email>" --to <email> --subject <subject> --body <text>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Inbox
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
mails inbox # List recent emails
|
|
75
|
+
mails inbox --mailbox agent@test.com # Specific mailbox
|
|
76
|
+
mails inbox <id> # View email details
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Verification Code
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
mails code --to agent@test.com # Wait for code (default 30s)
|
|
83
|
+
mails code --to agent@test.com --timeout 60 # Custom timeout
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The code is printed to stdout for easy piping: `CODE=$(mails code --to agent@test.com)`
|
|
87
|
+
|
|
88
|
+
### Config
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
mails config # Show all config
|
|
92
|
+
mails config set <key> <value> # Set a value
|
|
93
|
+
mails config get <key> # Get a value
|
|
94
|
+
mails config path # Show config file path
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## SDK Usage
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { send, getInbox, waitForCode } from 'mails'
|
|
101
|
+
|
|
102
|
+
// Send
|
|
103
|
+
const result = await send({
|
|
104
|
+
to: 'user@example.com',
|
|
105
|
+
subject: 'Hello',
|
|
106
|
+
text: 'World',
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// List inbox
|
|
110
|
+
const emails = await getInbox('agent@yourdomain.com', { limit: 10 })
|
|
111
|
+
|
|
112
|
+
// Wait for verification code
|
|
113
|
+
const code = await waitForCode('agent@yourdomain.com', { timeout: 30 })
|
|
114
|
+
if (code) console.log(code.code) // "123456"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Direct Provider Usage
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { createResendProvider } from 'mails'
|
|
121
|
+
|
|
122
|
+
const resend = createResendProvider('re_YOUR_KEY')
|
|
123
|
+
await resend.send({
|
|
124
|
+
from: 'Agent <agent@yourdomain.com>',
|
|
125
|
+
to: ['user@example.com'],
|
|
126
|
+
subject: 'Hello',
|
|
127
|
+
text: 'Direct provider usage',
|
|
128
|
+
})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Email Worker
|
|
132
|
+
|
|
133
|
+
The `worker/` directory contains a Cloudflare Email Routing Worker for receiving emails.
|
|
134
|
+
|
|
135
|
+
### Setup
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
cd worker
|
|
139
|
+
bun install
|
|
140
|
+
# Edit wrangler.toml — set your D1 database ID
|
|
141
|
+
wrangler d1 create mails
|
|
142
|
+
wrangler d1 execute mails --file=schema.sql
|
|
143
|
+
wrangler deploy
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Then configure Cloudflare Email Routing to forward to this worker.
|
|
147
|
+
|
|
148
|
+
### Worker API
|
|
149
|
+
|
|
150
|
+
| Endpoint | Description |
|
|
151
|
+
|----------|-------------|
|
|
152
|
+
| `GET /api/inbox?to=<addr>&limit=20` | List emails |
|
|
153
|
+
| `GET /api/code?to=<addr>&timeout=30` | Long-poll for verification code |
|
|
154
|
+
| `GET /api/email?id=<id>` | Get email by ID |
|
|
155
|
+
| `GET /health` | Health check |
|
|
156
|
+
|
|
157
|
+
## Storage Providers
|
|
158
|
+
|
|
159
|
+
### SQLite (default)
|
|
160
|
+
|
|
161
|
+
Local database at `~/.mails/mails.db`. Zero config.
|
|
162
|
+
|
|
163
|
+
### db9.ai
|
|
164
|
+
|
|
165
|
+
Cloud PostgreSQL for AI agents.
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
mails config set storage_provider db9
|
|
169
|
+
mails config set db9_token YOUR_TOKEN
|
|
170
|
+
mails config set db9_database_id YOUR_DB_ID
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Config Keys
|
|
174
|
+
|
|
175
|
+
| Key | Default | Description |
|
|
176
|
+
|-----|---------|-------------|
|
|
177
|
+
| `mode` | `hosted` | `hosted` or `selfhosted` |
|
|
178
|
+
| `domain` | `mails.dev` | Email domain |
|
|
179
|
+
| `mailbox` | | Your receiving address |
|
|
180
|
+
| `send_provider` | `resend` | Send provider |
|
|
181
|
+
| `storage_provider` | `sqlite` | `sqlite` or `db9` |
|
|
182
|
+
| `resend_api_key` | | Resend API key |
|
|
183
|
+
| `default_from` | | Default sender address |
|
|
184
|
+
| `db9_token` | | db9.ai API token |
|
|
185
|
+
| `db9_database_id` | | db9.ai database ID |
|
|
186
|
+
|
|
187
|
+
## Testing
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
bun test # Run all tests
|
|
191
|
+
bun test --coverage # With coverage report
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
MIT
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# mails
|
|
2
|
+
|
|
3
|
+
面向 AI Agent 的邮件基础设施。通过编程方式收发邮件。
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/mails)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
[English](README.md) | [日本語](README.ja.md)
|
|
9
|
+
|
|
10
|
+
## 测试覆盖率
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
全部文件: 100.00% Functions | 100.00% Lines
|
|
14
|
+
78 个单元测试 + 8 个 Live E2E 测试(真实 Resend + Cloudflare Email Routing)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 特性
|
|
18
|
+
|
|
19
|
+
- **发送邮件** — 通过 Resend(更多 Provider 即将支持)
|
|
20
|
+
- **接收邮件** — 通过 Cloudflare Email Routing Worker
|
|
21
|
+
- **验证码自动提取** — 自动从邮件中提取验证码(支持中/英/日/韩)
|
|
22
|
+
- **存储 Provider** — 本地 SQLite(默认)或 [db9.ai](https://db9.ai) 云端 PostgreSQL
|
|
23
|
+
- **零依赖** — Resend Provider 直接使用 `fetch()`,无需 SDK
|
|
24
|
+
- **Agent 优先** — 为 AI Agent 设计,附带 `skill.md` 接入指南
|
|
25
|
+
- **云服务** — `@mails.dev` 邮箱地址,x402 微支付(即将上线)
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g mails
|
|
31
|
+
# 或
|
|
32
|
+
bun install -g mails
|
|
33
|
+
# 或直接使用
|
|
34
|
+
npx mails
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 快速开始
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 配置
|
|
41
|
+
mails config set resend_api_key re_YOUR_KEY
|
|
42
|
+
mails config set default_from "Agent <agent@yourdomain.com>"
|
|
43
|
+
|
|
44
|
+
# 发送邮件
|
|
45
|
+
mails send --to user@example.com --subject "Hello" --body "World"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## CLI 参考
|
|
49
|
+
|
|
50
|
+
### 发送
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
mails send --to <email> --subject <subject> --body <text>
|
|
54
|
+
mails send --to <email> --subject <subject> --html "<h1>Hello</h1>"
|
|
55
|
+
mails send --from "Name <email>" --to <email> --subject <subject> --body <text>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 收件箱
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
mails inbox # 最近邮件列表
|
|
62
|
+
mails inbox --mailbox agent@test.com # 指定邮箱
|
|
63
|
+
mails inbox <id> # 查看邮件详情
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 验证码
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
mails code --to agent@test.com # 等待验证码(默认 30 秒)
|
|
70
|
+
mails code --to agent@test.com --timeout 60 # 自定义超时
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
验证码输出到 stdout,方便管道使用:`CODE=$(mails code --to agent@test.com)`
|
|
74
|
+
|
|
75
|
+
### 配置
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
mails config # 显示所有配置
|
|
79
|
+
mails config set <key> <value> # 设置值
|
|
80
|
+
mails config get <key> # 获取值
|
|
81
|
+
mails config path # 显示配置文件路径
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## SDK 用法
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { send, getInbox, waitForCode } from 'mails'
|
|
88
|
+
|
|
89
|
+
// 发送
|
|
90
|
+
const result = await send({
|
|
91
|
+
to: 'user@example.com',
|
|
92
|
+
subject: 'Hello',
|
|
93
|
+
text: 'World',
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// 收件箱列表
|
|
97
|
+
const emails = await getInbox('agent@yourdomain.com', { limit: 10 })
|
|
98
|
+
|
|
99
|
+
// 等待验证码
|
|
100
|
+
const code = await waitForCode('agent@yourdomain.com', { timeout: 30 })
|
|
101
|
+
if (code) console.log(code.code) // "123456"
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 邮件 Worker
|
|
105
|
+
|
|
106
|
+
`worker/` 目录包含 Cloudflare Email Routing Worker,用于接收邮件。
|
|
107
|
+
|
|
108
|
+
### 部署
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
cd worker
|
|
112
|
+
bun install
|
|
113
|
+
# 编辑 wrangler.toml — 设置你的 D1 数据库 ID
|
|
114
|
+
wrangler d1 create mails
|
|
115
|
+
wrangler d1 execute mails --file=schema.sql
|
|
116
|
+
wrangler deploy
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
然后在 Cloudflare Email Routing 中配置转发到此 Worker。
|
|
120
|
+
|
|
121
|
+
## 存储 Provider
|
|
122
|
+
|
|
123
|
+
### SQLite(默认)
|
|
124
|
+
|
|
125
|
+
本地数据库 `~/.mails/mails.db`,无需配置。
|
|
126
|
+
|
|
127
|
+
### db9.ai
|
|
128
|
+
|
|
129
|
+
面向 AI Agent 的云端 PostgreSQL。
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
mails config set storage_provider db9
|
|
133
|
+
mails config set db9_token YOUR_TOKEN
|
|
134
|
+
mails config set db9_database_id YOUR_DB_ID
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 配置项
|
|
138
|
+
|
|
139
|
+
| 键 | 默认值 | 说明 |
|
|
140
|
+
|---|--------|------|
|
|
141
|
+
| `mode` | `hosted` | `hosted` 或 `selfhosted` |
|
|
142
|
+
| `domain` | `mails.dev` | 邮件域名 |
|
|
143
|
+
| `mailbox` | | 接收邮箱地址 |
|
|
144
|
+
| `send_provider` | `resend` | 发送 Provider |
|
|
145
|
+
| `storage_provider` | `sqlite` | `sqlite` 或 `db9` |
|
|
146
|
+
| `resend_api_key` | | Resend API 密钥 |
|
|
147
|
+
| `default_from` | | 默认发件人地址 |
|
|
148
|
+
| `db9_token` | | db9.ai API Token |
|
|
149
|
+
| `db9_database_id` | | db9.ai 数据库 ID |
|
|
150
|
+
|
|
151
|
+
## 测试
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
bun test # 运行所有测试
|
|
155
|
+
bun test --coverage # 带覆盖率报告
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## 许可证
|
|
159
|
+
|
|
160
|
+
MIT
|