tempmail-sdk 1.0.1 → 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 +162 -72
- package/demo/poll-emails.ts +25 -40
- 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 +1 -1
- package/src/index.ts +54 -4
- package/src/normalize.ts +80 -0
- package/src/providers/awamail.ts +101 -0
- package/src/providers/chatgpt-org-uk.ts +3 -1
- package/src/providers/dropmail.ts +98 -0
- package/src/providers/linshi-email.ts +3 -1
- 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 +4 -2
- package/src/providers/tempmail.ts +3 -1
- package/src/types.ts +32 -28
- package/test/example.ts +16 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'awamail';
|
|
5
|
+
const BASE_URL = 'https://awamail.com/welcome';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS: Record<string, string> = {
|
|
8
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
|
9
|
+
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
|
10
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
11
|
+
'cache-control': 'no-cache',
|
|
12
|
+
'dnt': '1',
|
|
13
|
+
'origin': 'https://awamail.com',
|
|
14
|
+
'pragma': 'no-cache',
|
|
15
|
+
'referer': 'https://awamail.com/?lang=zh',
|
|
16
|
+
'sec-ch-ua': '"Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144"',
|
|
17
|
+
'sec-ch-ua-mobile': '?0',
|
|
18
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
19
|
+
'sec-fetch-dest': 'empty',
|
|
20
|
+
'sec-fetch-mode': 'cors',
|
|
21
|
+
'sec-fetch-site': 'same-origin',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 从 Set-Cookie 响应头中提取 awamail_session 值
|
|
26
|
+
*/
|
|
27
|
+
function extractSessionCookie(response: Response): string {
|
|
28
|
+
const setCookie = response.headers.get('set-cookie') || '';
|
|
29
|
+
const match = setCookie.match(/awamail_session=([^;]+)/);
|
|
30
|
+
return match ? `awamail_session=${match[1]}` : '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 创建临时邮箱
|
|
35
|
+
* API: POST /welcome/change_mailbox (空 body)
|
|
36
|
+
* 返回: { success, data: { email_address, expired_at, created_at, ... } }
|
|
37
|
+
* 需要保存响应中的 Set-Cookie (awamail_session) 用于后续获取邮件
|
|
38
|
+
*/
|
|
39
|
+
export async function generateEmail(): Promise<EmailInfo> {
|
|
40
|
+
const response = await fetch(`${BASE_URL}/change_mailbox`, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: {
|
|
43
|
+
...DEFAULT_HEADERS,
|
|
44
|
+
'Content-Length': '0',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(`Failed to generate email: ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 提取 session cookie
|
|
53
|
+
const sessionCookie = extractSessionCookie(response);
|
|
54
|
+
if (!sessionCookie) {
|
|
55
|
+
throw new Error('Failed to extract session cookie');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
|
|
60
|
+
if (!data.success || !data.data) {
|
|
61
|
+
throw new Error('Failed to generate email');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
channel: CHANNEL,
|
|
66
|
+
email: data.data.email_address,
|
|
67
|
+
token: sessionCookie,
|
|
68
|
+
expiresAt: data.data.expired_at,
|
|
69
|
+
createdAt: data.data.created_at,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 获取邮件列表
|
|
75
|
+
* API: GET /welcome/get_emails
|
|
76
|
+
* 需要传入 Cookie (awamail_session) 和 x-requested-with 头
|
|
77
|
+
* 返回: { success, data: { emails: [...], latest: {...} } }
|
|
78
|
+
*/
|
|
79
|
+
export async function getEmails(token: string, email: string): Promise<Email[]> {
|
|
80
|
+
const response = await fetch(`${BASE_URL}/get_emails`, {
|
|
81
|
+
method: 'GET',
|
|
82
|
+
headers: {
|
|
83
|
+
...DEFAULT_HEADERS,
|
|
84
|
+
'Cookie': token,
|
|
85
|
+
'x-requested-with': 'XMLHttpRequest',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new Error(`Failed to get emails: ${response.status}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const data = await response.json();
|
|
94
|
+
|
|
95
|
+
if (!data.success || !data.data) {
|
|
96
|
+
throw new Error('Failed to get emails');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const rawEmails = data.data.emails || [];
|
|
100
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
101
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
2
3
|
|
|
3
4
|
const CHANNEL: Channel = 'chatgpt-org-uk';
|
|
4
5
|
const BASE_URL = 'https://mail.chatgpt.org.uk/api';
|
|
@@ -53,5 +54,6 @@ export async function getEmails(email: string): Promise<Email[]> {
|
|
|
53
54
|
throw new Error('Failed to get emails');
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
const rawEmails = data.data?.emails || [];
|
|
58
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
57
59
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'dropmail';
|
|
5
|
+
const BASE_URL = 'https://dropmail.me/api/graphql/MY_TOKEN';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS: Record<string, string> = {
|
|
8
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const CREATE_SESSION_QUERY = 'mutation {introduceSession {id, expiresAt, addresses{id, address}}}';
|
|
12
|
+
|
|
13
|
+
const GET_MAILS_QUERY = `query ($id: ID!) {
|
|
14
|
+
session(id:$id) {
|
|
15
|
+
mails {
|
|
16
|
+
id, rawSize, fromAddr, toAddr, receivedAt,
|
|
17
|
+
text, headerFrom, headerSubject, html
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 执行 GraphQL 请求
|
|
24
|
+
*/
|
|
25
|
+
async function graphqlRequest(query: string, variables?: Record<string, any>): Promise<any> {
|
|
26
|
+
const params = new URLSearchParams();
|
|
27
|
+
params.set('query', query);
|
|
28
|
+
if (variables) {
|
|
29
|
+
params.set('variables', JSON.stringify(variables));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const response = await fetch(BASE_URL, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: DEFAULT_HEADERS,
|
|
35
|
+
body: params.toString(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`GraphQL request failed: ${response.status}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
|
|
44
|
+
if (data.errors) {
|
|
45
|
+
throw new Error(`GraphQL error: ${data.errors[0]?.message || 'Unknown error'}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return data.data;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 创建临时邮箱
|
|
53
|
+
* GraphQL mutation: introduceSession
|
|
54
|
+
* 返回 session ID (存入 token) 和邮箱地址
|
|
55
|
+
*/
|
|
56
|
+
export async function generateEmail(): Promise<EmailInfo> {
|
|
57
|
+
const data = await graphqlRequest(CREATE_SESSION_QUERY);
|
|
58
|
+
|
|
59
|
+
const session = data?.introduceSession;
|
|
60
|
+
if (!session || !session.addresses || session.addresses.length === 0) {
|
|
61
|
+
throw new Error('Failed to generate email');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
channel: CHANNEL,
|
|
66
|
+
email: session.addresses[0].address,
|
|
67
|
+
token: session.id,
|
|
68
|
+
expiresAt: session.expiresAt,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 将 dropmail 的邮件格式扁平化为 normalizeEmail 可处理的格式
|
|
74
|
+
*/
|
|
75
|
+
function flattenMessage(mail: any, recipientEmail: string): any {
|
|
76
|
+
return {
|
|
77
|
+
id: mail.id || '',
|
|
78
|
+
from: mail.fromAddr || '',
|
|
79
|
+
to: mail.toAddr || recipientEmail,
|
|
80
|
+
subject: mail.headerSubject || '',
|
|
81
|
+
text: mail.text || '',
|
|
82
|
+
html: mail.html || '',
|
|
83
|
+
received_at: mail.receivedAt || '',
|
|
84
|
+
attachments: [],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 获取邮件列表
|
|
90
|
+
* GraphQL query: session(id) { mails {...} }
|
|
91
|
+
* token 中存储的是 session ID
|
|
92
|
+
*/
|
|
93
|
+
export async function getEmails(token: string, email: string): Promise<Email[]> {
|
|
94
|
+
const data = await graphqlRequest(GET_MAILS_QUERY, { id: token });
|
|
95
|
+
|
|
96
|
+
const mails = data?.session?.mails || [];
|
|
97
|
+
return mails.map((mail: any) => normalizeEmail(flattenMessage(mail, email), email));
|
|
98
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
2
3
|
|
|
3
4
|
const CHANNEL: Channel = 'linshi-email';
|
|
4
5
|
const BASE_URL = 'https://www.linshi-email.com/api/v1';
|
|
@@ -57,5 +58,6 @@ export async function getEmails(email: string): Promise<Email[]> {
|
|
|
57
58
|
throw new Error('Failed to get emails');
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
const rawEmails = data.list || [];
|
|
62
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
61
63
|
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'mail-tm';
|
|
5
|
+
const BASE_URL = 'https://api.mail.tm';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS: Record<string, string> = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
'Accept': 'application/json',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 生成随机字符串
|
|
14
|
+
*/
|
|
15
|
+
function randomString(length: number): string {
|
|
16
|
+
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
17
|
+
let result = '';
|
|
18
|
+
for (let i = 0; i < length; i++) {
|
|
19
|
+
result += chars[Math.floor(Math.random() * chars.length)];
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 获取可用域名列表
|
|
26
|
+
* API: GET /domains
|
|
27
|
+
*/
|
|
28
|
+
async function getDomains(): Promise<string[]> {
|
|
29
|
+
const response = await fetch(`${BASE_URL}/domains`, {
|
|
30
|
+
method: 'GET',
|
|
31
|
+
headers: DEFAULT_HEADERS,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
throw new Error(`Failed to get domains: ${response.status}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
const members = data['hydra:member'] || [];
|
|
40
|
+
return members
|
|
41
|
+
.filter((d: any) => d.isActive)
|
|
42
|
+
.map((d: any) => d.domain);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 创建账号
|
|
47
|
+
* API: POST /accounts
|
|
48
|
+
*/
|
|
49
|
+
async function createAccount(address: string, password: string): Promise<any> {
|
|
50
|
+
const response = await fetch(`${BASE_URL}/accounts`, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { ...DEFAULT_HEADERS, 'Content-Type': 'application/ld+json' },
|
|
53
|
+
body: JSON.stringify({ address, password }),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
const text = await response.text();
|
|
58
|
+
throw new Error(`Failed to create account: ${response.status} ${text}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return response.json();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 获取 Bearer Token
|
|
66
|
+
* API: POST /token
|
|
67
|
+
*/
|
|
68
|
+
async function getToken(address: string, password: string): Promise<string> {
|
|
69
|
+
const response = await fetch(`${BASE_URL}/token`, {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: DEFAULT_HEADERS,
|
|
72
|
+
body: JSON.stringify({ address, password }),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new Error(`Failed to get token: ${response.status}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const data = await response.json();
|
|
80
|
+
return data.token;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 创建临时邮箱
|
|
85
|
+
* 流程: 获取域名 → 生成随机邮箱/密码 → 创建账号 → 获取 Token
|
|
86
|
+
*/
|
|
87
|
+
export async function generateEmail(): Promise<EmailInfo> {
|
|
88
|
+
// 1. 获取可用域名
|
|
89
|
+
const domains = await getDomains();
|
|
90
|
+
if (domains.length === 0) {
|
|
91
|
+
throw new Error('No available domains');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 2. 生成随机邮箱和密码
|
|
95
|
+
const domain = domains[Math.floor(Math.random() * domains.length)];
|
|
96
|
+
const username = randomString(12);
|
|
97
|
+
const address = `${username}@${domain}`;
|
|
98
|
+
const password = randomString(16);
|
|
99
|
+
|
|
100
|
+
// 3. 创建账号
|
|
101
|
+
const account = await createAccount(address, password);
|
|
102
|
+
|
|
103
|
+
// 4. 获取 Bearer Token
|
|
104
|
+
const token = await getToken(address, password);
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
channel: CHANNEL,
|
|
108
|
+
email: address,
|
|
109
|
+
token: token,
|
|
110
|
+
createdAt: account.createdAt,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 将 mail.tm 的消息格式扁平化为 normalizeEmail 可处理的格式
|
|
116
|
+
* mail.tm 的 from 是 {name, address} 对象,to 是数组,html 是字符串数组
|
|
117
|
+
*/
|
|
118
|
+
function flattenMessage(msg: any, recipientEmail: string): any {
|
|
119
|
+
return {
|
|
120
|
+
id: msg.id || '',
|
|
121
|
+
from: msg.from?.address || '',
|
|
122
|
+
to: msg.to?.[0]?.address || recipientEmail,
|
|
123
|
+
subject: msg.subject || '',
|
|
124
|
+
text: msg.text || '',
|
|
125
|
+
html: Array.isArray(msg.html) ? msg.html.join('') : (msg.html || ''),
|
|
126
|
+
createdAt: msg.createdAt || '',
|
|
127
|
+
seen: msg.seen ?? false,
|
|
128
|
+
attachments: (msg.attachments || []).map((a: any) => ({
|
|
129
|
+
filename: a.filename || '',
|
|
130
|
+
size: a.size || undefined,
|
|
131
|
+
contentType: a.contentType || undefined,
|
|
132
|
+
downloadUrl: a.downloadUrl ? `${BASE_URL}${a.downloadUrl}` : undefined,
|
|
133
|
+
})),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 获取邮件列表
|
|
139
|
+
* 流程: GET /messages 获取列表 → 对每封邮件 GET /messages/{id} 获取详情(含 text/html)
|
|
140
|
+
*/
|
|
141
|
+
export async function getEmails(token: string, email: string): Promise<Email[]> {
|
|
142
|
+
// 1. 获取邮件列表
|
|
143
|
+
const listResponse = await fetch(`${BASE_URL}/messages`, {
|
|
144
|
+
method: 'GET',
|
|
145
|
+
headers: {
|
|
146
|
+
...DEFAULT_HEADERS,
|
|
147
|
+
'Authorization': `Bearer ${token}`,
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (!listResponse.ok) {
|
|
152
|
+
throw new Error(`Failed to get emails: ${listResponse.status}`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const listData = await listResponse.json();
|
|
156
|
+
const messages = listData['hydra:member'] || [];
|
|
157
|
+
|
|
158
|
+
if (messages.length === 0) {
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 2. 并行获取每封邮件的详情(含 text/html/attachments)
|
|
163
|
+
const detailPromises = messages.map(async (msg: any) => {
|
|
164
|
+
try {
|
|
165
|
+
const detailResponse = await fetch(`${BASE_URL}/messages/${msg.id}`, {
|
|
166
|
+
method: 'GET',
|
|
167
|
+
headers: {
|
|
168
|
+
...DEFAULT_HEADERS,
|
|
169
|
+
'Authorization': `Bearer ${token}`,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!detailResponse.ok) {
|
|
174
|
+
// 如果详情获取失败,退回使用列表数据
|
|
175
|
+
return flattenMessage(msg, email);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const detail = await detailResponse.json();
|
|
179
|
+
return flattenMessage(detail, email);
|
|
180
|
+
} catch {
|
|
181
|
+
// 出错时退回使用列表数据
|
|
182
|
+
return flattenMessage(msg, email);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const flatMessages = await Promise.all(detailPromises);
|
|
187
|
+
return flatMessages.map((raw: any) => normalizeEmail(raw, email));
|
|
188
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'temp-mail-io';
|
|
5
|
+
const BASE_URL = 'https://api.internal.temp-mail.io/api/v3';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS: Record<string, string> = {
|
|
8
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
11
|
+
'application-name': 'web',
|
|
12
|
+
'application-version': '4.0.0',
|
|
13
|
+
'cache-control': 'no-cache',
|
|
14
|
+
'dnt': '1',
|
|
15
|
+
'origin': 'https://temp-mail.io',
|
|
16
|
+
'pragma': 'no-cache',
|
|
17
|
+
'referer': 'https://temp-mail.io/',
|
|
18
|
+
'sec-ch-ua': '"Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144"',
|
|
19
|
+
'sec-ch-ua-mobile': '?0',
|
|
20
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
21
|
+
'sec-fetch-dest': 'empty',
|
|
22
|
+
'sec-fetch-mode': 'cors',
|
|
23
|
+
'sec-fetch-site': 'same-site',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 创建临时邮箱
|
|
28
|
+
* API: POST /api/v3/email/new
|
|
29
|
+
* 返回: { email, token }
|
|
30
|
+
*/
|
|
31
|
+
export async function generateEmail(): Promise<EmailInfo> {
|
|
32
|
+
const response = await fetch(`${BASE_URL}/email/new`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: DEFAULT_HEADERS,
|
|
35
|
+
body: JSON.stringify({ min_name_length: 100, max_name_length: 100 }),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Failed to generate email: ${response.status}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
|
|
44
|
+
if (!data.email || !data.token) {
|
|
45
|
+
throw new Error('Failed to generate email');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
channel: CHANNEL,
|
|
50
|
+
email: data.email,
|
|
51
|
+
token: data.token,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取邮件列表
|
|
57
|
+
* API: GET /api/v3/email/{email}/messages
|
|
58
|
+
* 返回: [ { id, from, to, cc, subject, body_text, body_html, created_at, attachments } ]
|
|
59
|
+
*/
|
|
60
|
+
export async function getEmails(email: string): Promise<Email[]> {
|
|
61
|
+
const encodedEmail = encodeURIComponent(email);
|
|
62
|
+
const response = await fetch(`${BASE_URL}/email/${encodedEmail}/messages`, {
|
|
63
|
+
method: 'GET',
|
|
64
|
+
headers: DEFAULT_HEADERS,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
throw new Error(`Failed to get emails: ${response.status}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const data = await response.json();
|
|
72
|
+
|
|
73
|
+
// API 直接返回邮件数组
|
|
74
|
+
const rawEmails = Array.isArray(data) ? data : [];
|
|
75
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
76
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'tempmail-la';
|
|
5
|
+
const BASE_URL = 'https://tempmail.la/api';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS: Record<string, string> = {
|
|
8
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0',
|
|
9
|
+
'Accept': 'application/json, text/plain, */*',
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
12
|
+
'cache-control': 'no-cache',
|
|
13
|
+
'dnt': '1',
|
|
14
|
+
'locale': 'zh-CN',
|
|
15
|
+
'origin': 'https://tempmail.la',
|
|
16
|
+
'platform': 'PC',
|
|
17
|
+
'pragma': 'no-cache',
|
|
18
|
+
'product': 'TEMP_MAIL',
|
|
19
|
+
'referer': 'https://tempmail.la/zh-CN/tempmail',
|
|
20
|
+
'sec-ch-ua': '"Not(A:Brand";v="8", "Chromium";v="144", "Microsoft Edge";v="144"',
|
|
21
|
+
'sec-ch-ua-mobile': '?0',
|
|
22
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
23
|
+
'sec-fetch-dest': 'empty',
|
|
24
|
+
'sec-fetch-mode': 'cors',
|
|
25
|
+
'sec-fetch-site': 'same-origin',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 创建临时邮箱
|
|
30
|
+
* API: POST /api/mail/create
|
|
31
|
+
* 返回: { code: 0, data: { mailId, address, type, startAt, endAt } }
|
|
32
|
+
*/
|
|
33
|
+
export async function generateEmail(): Promise<EmailInfo> {
|
|
34
|
+
const response = await fetch(`${BASE_URL}/mail/create`, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: DEFAULT_HEADERS,
|
|
37
|
+
body: JSON.stringify({ turnstile: '' }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
throw new Error(`Failed to generate email: ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
|
|
46
|
+
if (data.code !== 0 || !data.data) {
|
|
47
|
+
throw new Error('Failed to generate email');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
channel: CHANNEL,
|
|
52
|
+
email: data.data.address,
|
|
53
|
+
expiresAt: data.data.endAt,
|
|
54
|
+
createdAt: data.data.startAt,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取邮件列表
|
|
60
|
+
* API: POST /api/mail/box
|
|
61
|
+
* 请求: { address, cursor }
|
|
62
|
+
* 返回: { code: 0, data: { rows: [...], cursor, hasMore } }
|
|
63
|
+
* 每封邮件: { mailboxId, messageFrom, subject, createdAt, html, attachments, read }
|
|
64
|
+
*/
|
|
65
|
+
export async function getEmails(email: string): Promise<Email[]> {
|
|
66
|
+
const allEmails: any[] = [];
|
|
67
|
+
let cursor: string | null = null;
|
|
68
|
+
let hasMore = true;
|
|
69
|
+
|
|
70
|
+
// 支持分页,循环获取所有邮件
|
|
71
|
+
while (hasMore) {
|
|
72
|
+
const response: Response = await fetch(`${BASE_URL}/mail/box`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: DEFAULT_HEADERS,
|
|
75
|
+
body: JSON.stringify({ address: email, cursor }),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(`Failed to get emails: ${response.status}`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const data: any = await response.json();
|
|
83
|
+
|
|
84
|
+
if (data.code !== 0 || !data.data) {
|
|
85
|
+
throw new Error('Failed to get emails');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const rows = data.data.rows || [];
|
|
89
|
+
allEmails.push(...rows);
|
|
90
|
+
|
|
91
|
+
if (data.data.hasMore && data.data.cursor) {
|
|
92
|
+
cursor = data.data.cursor;
|
|
93
|
+
} else {
|
|
94
|
+
hasMore = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return allEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
99
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
2
3
|
|
|
3
4
|
const CHANNEL: Channel = 'tempmail-lol';
|
|
4
5
|
const BASE_URL = 'https://api.tempmail.lol/v2';
|
|
@@ -37,7 +38,7 @@ export async function generateEmail(domain: string | null = null): Promise<Email
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export async function getEmails(token: string): Promise<Email[]> {
|
|
41
|
+
export async function getEmails(token: string, recipientEmail: string = ''): Promise<Email[]> {
|
|
41
42
|
const response = await fetch(`${BASE_URL}/inbox?token=${encodeURIComponent(token)}`, {
|
|
42
43
|
method: 'GET',
|
|
43
44
|
headers: DEFAULT_HEADERS,
|
|
@@ -49,5 +50,6 @@ export async function getEmails(token: string): Promise<Email[]> {
|
|
|
49
50
|
|
|
50
51
|
const data = await response.json();
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
const rawEmails = data.emails || [];
|
|
54
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, recipientEmail));
|
|
53
55
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
2
3
|
|
|
3
4
|
const CHANNEL: Channel = 'tempmail';
|
|
4
5
|
const BASE_URL = 'https://api.tempmail.ing/api';
|
|
@@ -55,5 +56,6 @@ export async function getEmails(email: string): Promise<Email[]> {
|
|
|
55
56
|
throw new Error('Failed to get emails');
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
const rawEmails = data.emails || [];
|
|
60
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
59
61
|
}
|