tempmail-sdk 1.0.0 → 1.0.2
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.md +243 -153
- package/demo/poll-emails.ts +172 -187
- package/dist/index.d.ts +2 -1
- package/dist/index.js +55 -4
- package/dist/normalize.d.ts +5 -0
- package/dist/normalize.js +87 -0
- package/dist/providers/awamail.d.ts +15 -0
- package/dist/providers/awamail.js +91 -0
- package/dist/providers/chatgpt-org-uk.js +4 -2
- package/dist/providers/dropmail.d.ts +13 -0
- package/dist/providers/dropmail.js +86 -0
- package/dist/providers/linshi-email.js +4 -2
- package/dist/providers/mail-tm.d.ts +11 -0
- package/dist/providers/mail-tm.js +167 -0
- package/dist/providers/temp-mail-io.d.ts +13 -0
- package/dist/providers/temp-mail-io.js +69 -0
- package/dist/providers/tempmail-la.d.ts +15 -0
- package/dist/providers/tempmail-la.js +89 -0
- package/dist/providers/tempmail-lol.d.ts +1 -1
- package/dist/providers/tempmail-lol.js +5 -3
- package/dist/providers/tempmail.js +4 -2
- package/dist/types.d.ts +31 -28
- package/dist/types.js +1 -1
- package/package.json +37 -37
- package/src/global.d.ts +5 -5
- package/src/index.ts +183 -133
- package/src/normalize.ts +80 -0
- package/src/providers/awamail.ts +101 -0
- package/src/providers/chatgpt-org-uk.ts +59 -57
- package/src/providers/dropmail.ts +98 -0
- package/src/providers/linshi-email.ts +63 -61
- package/src/providers/mail-tm.ts +188 -0
- package/src/providers/temp-mail-io.ts +76 -0
- package/src/providers/tempmail-la.ts +99 -0
- package/src/providers/tempmail-lol.ts +55 -53
- package/src/providers/tempmail.ts +61 -59
- package/src/types.ts +62 -58
- package/test/example.ts +63 -48
- package/tsconfig.json +27 -27
package/README.md
CHANGED
|
@@ -1,153 +1,243 @@
|
|
|
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
|
-
console.log(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.log(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
```typescript
|
|
87
|
-
import {
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
1
|
+
# tempmail-sdk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/tempmail-sdk)
|
|
4
|
+
[](https://www.gnu.org/licenses/gpl-3.0)
|
|
5
|
+
|
|
6
|
+
临时邮箱 SDK(TypeScript/Node.js),支持 9 个邮箱服务提供商,所有渠道返回**统一标准化格式**。
|
|
7
|
+
|
|
8
|
+
## 安装
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install tempmail-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 支持的渠道
|
|
15
|
+
|
|
16
|
+
| 渠道 | 服务商 | 需要 Token | 说明 |
|
|
17
|
+
|------|--------|:----------:|------|
|
|
18
|
+
| `tempmail` | tempmail.ing | - | 支持自定义有效期 |
|
|
19
|
+
| `linshi-email` | linshi-email.com | - | |
|
|
20
|
+
| `tempmail-lol` | tempmail.lol | ✅ | 支持指定域名 |
|
|
21
|
+
| `chatgpt-org-uk` | mail.chatgpt.org.uk | - | |
|
|
22
|
+
| `tempmail-la` | tempmail.la | - | 支持分页 |
|
|
23
|
+
| `temp-mail-io` | temp-mail.io | - | |
|
|
24
|
+
| `awamail` | awamail.com | ✅ | Session Cookie 自动管理 |
|
|
25
|
+
| `mail-tm` | mail.tm | ✅ | 自动注册账号获取 Bearer Token |
|
|
26
|
+
| `dropmail` | dropmail.me | ✅ | GraphQL API |
|
|
27
|
+
|
|
28
|
+
> **提示:** 使用 `TempEmailClient` 类时无需手动处理 Token,SDK 自动管理。
|
|
29
|
+
|
|
30
|
+
## 快速开始
|
|
31
|
+
|
|
32
|
+
### 使用 TempEmailClient(推荐)
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { TempEmailClient } from 'tempmail-sdk';
|
|
36
|
+
|
|
37
|
+
const client = new TempEmailClient();
|
|
38
|
+
|
|
39
|
+
// 获取临时邮箱(可指定渠道,不指定则随机)
|
|
40
|
+
const emailInfo = await client.generate({ channel: 'tempmail' });
|
|
41
|
+
console.log(`渠道: ${emailInfo.channel}`);
|
|
42
|
+
console.log(`邮箱: ${emailInfo.email}`);
|
|
43
|
+
if (emailInfo.expiresAt) console.log(`过期时间: ${emailInfo.expiresAt}`);
|
|
44
|
+
|
|
45
|
+
// 获取邮件(Token 自动传递,无需手动处理)
|
|
46
|
+
const result = await client.getEmails();
|
|
47
|
+
console.log(`收到 ${result.emails.length} 封邮件`);
|
|
48
|
+
|
|
49
|
+
for (const email of result.emails) {
|
|
50
|
+
console.log(`发件人: ${email.from}`);
|
|
51
|
+
console.log(`主题: ${email.subject}`);
|
|
52
|
+
console.log(`内容: ${email.text}`);
|
|
53
|
+
console.log(`时间: ${email.date}`);
|
|
54
|
+
console.log(`已读: ${email.isRead}`);
|
|
55
|
+
console.log(`附件: ${email.attachments.length} 个`);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 使用函数式 API
|
|
60
|
+
|
|
61
|
+
#### 列出所有渠道
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { listChannels, getChannelInfo } from 'tempmail-sdk';
|
|
65
|
+
|
|
66
|
+
const channels = listChannels();
|
|
67
|
+
console.log(channels);
|
|
68
|
+
// [
|
|
69
|
+
// { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' },
|
|
70
|
+
// { channel: 'linshi-email', name: '临时邮箱', website: 'linshi-email.com' },
|
|
71
|
+
// { channel: 'tempmail-lol', name: 'TempMail LOL', website: 'tempmail.lol' },
|
|
72
|
+
// { channel: 'chatgpt-org-uk', name: 'ChatGPT Mail', website: 'mail.chatgpt.org.uk' },
|
|
73
|
+
// { channel: 'tempmail-la', name: 'TempMail LA', website: 'tempmail.la' },
|
|
74
|
+
// { channel: 'temp-mail-io', name: 'Temp Mail IO', website: 'temp-mail.io' },
|
|
75
|
+
// { channel: 'awamail', name: 'AwaMail', website: 'awamail.com' },
|
|
76
|
+
// { channel: 'mail-tm', name: 'Mail.tm', website: 'mail.tm' },
|
|
77
|
+
// { channel: 'dropmail', name: 'DropMail', website: 'dropmail.me' }
|
|
78
|
+
// ]
|
|
79
|
+
|
|
80
|
+
const info = getChannelInfo('tempmail');
|
|
81
|
+
// { channel: 'tempmail', name: 'TempMail', website: 'tempmail.ing' }
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
#### 获取邮箱
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { generateEmail } from 'tempmail-sdk';
|
|
88
|
+
|
|
89
|
+
// 从随机渠道获取邮箱
|
|
90
|
+
const emailInfo = await generateEmail();
|
|
91
|
+
console.log(emailInfo);
|
|
92
|
+
// { channel: 'tempmail', email: 'xxx@ibymail.com', expiresAt: '...' }
|
|
93
|
+
|
|
94
|
+
// 从指定渠道获取邮箱
|
|
95
|
+
const emailInfo2 = await generateEmail({ channel: 'linshi-email' });
|
|
96
|
+
|
|
97
|
+
// tempmail 渠道支持自定义有效期(分钟)
|
|
98
|
+
const emailInfo3 = await generateEmail({ channel: 'tempmail', duration: 60 });
|
|
99
|
+
|
|
100
|
+
// tempmail-lol 渠道支持指定域名
|
|
101
|
+
const emailInfo4 = await generateEmail({ channel: 'tempmail-lol', domain: 'example.com' });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### 获取邮件
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { getEmails } from 'tempmail-sdk';
|
|
108
|
+
|
|
109
|
+
// 不需要 Token 的渠道
|
|
110
|
+
const result = await getEmails({
|
|
111
|
+
channel: 'tempmail',
|
|
112
|
+
email: 'xxx@ibymail.com',
|
|
113
|
+
});
|
|
114
|
+
console.log(result.emails); // 标准化邮件数组
|
|
115
|
+
|
|
116
|
+
// 需要 Token 的渠道(token 由 generateEmail 返回)
|
|
117
|
+
const result2 = await getEmails({
|
|
118
|
+
channel: 'mail-tm',
|
|
119
|
+
email: emailInfo.email,
|
|
120
|
+
token: emailInfo.token, // Bearer Token
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// 所有邮件使用统一格式,无需关心渠道差异
|
|
124
|
+
for (const email of result2.emails) {
|
|
125
|
+
console.log(email.id); // 邮件 ID
|
|
126
|
+
console.log(email.from); // 发件人
|
|
127
|
+
console.log(email.to); // 收件人
|
|
128
|
+
console.log(email.subject); // 主题
|
|
129
|
+
console.log(email.text); // 纯文本
|
|
130
|
+
console.log(email.html); // HTML
|
|
131
|
+
console.log(email.date); // ISO 日期
|
|
132
|
+
console.log(email.isRead); // 是否已读
|
|
133
|
+
console.log(email.attachments); // 附件列表
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API 参考
|
|
138
|
+
|
|
139
|
+
### listChannels()
|
|
140
|
+
|
|
141
|
+
获取所有支持的渠道列表。
|
|
142
|
+
|
|
143
|
+
**返回值:** `ChannelInfo[]`
|
|
144
|
+
|
|
145
|
+
| 字段 | 类型 | 说明 |
|
|
146
|
+
|------|------|------|
|
|
147
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
148
|
+
| `name` | `string` | 渠道显示名称 |
|
|
149
|
+
| `website` | `string` | 服务商网站 |
|
|
150
|
+
|
|
151
|
+
### getChannelInfo(channel)
|
|
152
|
+
|
|
153
|
+
获取指定渠道信息。
|
|
154
|
+
|
|
155
|
+
**返回值:** `ChannelInfo | undefined`
|
|
156
|
+
|
|
157
|
+
### generateEmail(options?)
|
|
158
|
+
|
|
159
|
+
生成临时邮箱地址。
|
|
160
|
+
|
|
161
|
+
**参数:**
|
|
162
|
+
|
|
163
|
+
| 字段 | 类型 | 说明 |
|
|
164
|
+
|------|------|------|
|
|
165
|
+
| `channel` | `Channel` | 指定渠道(可选,不指定则随机) |
|
|
166
|
+
| `duration` | `number` | 有效期分钟数(仅 `tempmail` 渠道) |
|
|
167
|
+
| `domain` | `string` | 指定域名(仅 `tempmail-lol` 渠道) |
|
|
168
|
+
|
|
169
|
+
**返回值:** `EmailInfo`
|
|
170
|
+
|
|
171
|
+
| 字段 | 类型 | 说明 |
|
|
172
|
+
|------|------|------|
|
|
173
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
174
|
+
| `email` | `string` | 邮箱地址 |
|
|
175
|
+
| `token` | `string?` | 访问令牌(部分渠道返回) |
|
|
176
|
+
| `expiresAt` | `string \| number?` | 过期时间 |
|
|
177
|
+
| `createdAt` | `string?` | 创建时间 |
|
|
178
|
+
|
|
179
|
+
### getEmails(options)
|
|
180
|
+
|
|
181
|
+
获取邮件列表。
|
|
182
|
+
|
|
183
|
+
**参数:**
|
|
184
|
+
|
|
185
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
186
|
+
|------|------|:----:|------|
|
|
187
|
+
| `channel` | `Channel` | ✅ | 渠道标识 |
|
|
188
|
+
| `email` | `string` | ✅ | 邮箱地址 |
|
|
189
|
+
| `token` | `string` | 部分 | 访问令牌(`tempmail-lol`、`awamail`、`mail-tm`、`dropmail` 必填) |
|
|
190
|
+
|
|
191
|
+
**返回值:** `GetEmailsResult`
|
|
192
|
+
|
|
193
|
+
| 字段 | 类型 | 说明 |
|
|
194
|
+
|------|------|------|
|
|
195
|
+
| `channel` | `Channel` | 渠道标识 |
|
|
196
|
+
| `email` | `string` | 邮箱地址 |
|
|
197
|
+
| `emails` | `Email[]` | 标准化邮件数组 |
|
|
198
|
+
| `success` | `boolean` | 是否成功 |
|
|
199
|
+
|
|
200
|
+
### 标准化邮件格式
|
|
201
|
+
|
|
202
|
+
所有渠道返回的邮件均使用统一的 `Email` 格式:
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
interface Email {
|
|
206
|
+
id: string; // 邮件唯一标识
|
|
207
|
+
from: string; // 发件人邮箱地址
|
|
208
|
+
to: string; // 收件人邮箱地址
|
|
209
|
+
subject: string; // 邮件主题
|
|
210
|
+
text: string; // 纯文本内容
|
|
211
|
+
html: string; // HTML 内容
|
|
212
|
+
date: string; // ISO 8601 格式日期
|
|
213
|
+
isRead: boolean; // 是否已读
|
|
214
|
+
attachments: EmailAttachment[]; // 附件列表
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
interface EmailAttachment {
|
|
218
|
+
filename: string; // 文件名
|
|
219
|
+
size?: number; // 文件大小(字节)
|
|
220
|
+
contentType?: string; // MIME 类型
|
|
221
|
+
url?: string; // 下载地址
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### TempEmailClient 类
|
|
226
|
+
|
|
227
|
+
封装了 Token 自动管理的便捷客户端:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
const client = new TempEmailClient();
|
|
231
|
+
await client.generate(options?); // 生成邮箱
|
|
232
|
+
await client.getEmails(); // 获取邮件(自动传递 token)
|
|
233
|
+
client.getEmailInfo(); // 获取当前邮箱信息
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## 环境要求
|
|
237
|
+
|
|
238
|
+
- Node.js 18+(需要原生 `fetch` 支持)
|
|
239
|
+
- TypeScript 5.0+(类型定义)
|
|
240
|
+
|
|
241
|
+
## 许可证
|
|
242
|
+
|
|
243
|
+
GPL-3.0
|