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
|
@@ -1,53 +1,55 @@
|
|
|
1
|
-
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'sec-ch-ua
|
|
12
|
-
'sec-ch-ua-
|
|
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
|
-
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'tempmail-lol';
|
|
5
|
+
const BASE_URL = 'https://api.tempmail.lol/v2';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS = {
|
|
8
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'Origin': 'https://tempmail.lol',
|
|
11
|
+
'sec-ch-ua': '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
12
|
+
'sec-ch-ua-mobile': '?0',
|
|
13
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
14
|
+
'DNT': '1',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function generateEmail(domain: string | null = null): Promise<EmailInfo> {
|
|
18
|
+
const response = await fetch(`${BASE_URL}/inbox/create`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: DEFAULT_HEADERS,
|
|
21
|
+
body: JSON.stringify({ domain, captcha: null }),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`Failed to generate email: ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
|
|
30
|
+
if (!data.address || !data.token) {
|
|
31
|
+
throw new Error('Failed to generate email');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
channel: CHANNEL,
|
|
36
|
+
email: data.address,
|
|
37
|
+
token: data.token,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function getEmails(token: string, recipientEmail: string = ''): Promise<Email[]> {
|
|
42
|
+
const response = await fetch(`${BASE_URL}/inbox?token=${encodeURIComponent(token)}`, {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
headers: DEFAULT_HEADERS,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error(`Failed to get emails: ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
|
|
53
|
+
const rawEmails = data.emails || [];
|
|
54
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, recipientEmail));
|
|
55
|
+
}
|
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'sec-ch-ua
|
|
12
|
-
'sec-ch-ua-
|
|
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
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import { EmailInfo, Email, Channel } from '../types';
|
|
2
|
+
import { normalizeEmail } from '../normalize';
|
|
3
|
+
|
|
4
|
+
const CHANNEL: Channel = 'tempmail';
|
|
5
|
+
const BASE_URL = 'https://api.tempmail.ing/api';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_HEADERS = {
|
|
8
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
'Referer': 'https://tempmail.ing/',
|
|
11
|
+
'sec-ch-ua': '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
|
|
12
|
+
'sec-ch-ua-mobile': '?0',
|
|
13
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
14
|
+
'DNT': '1',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export async function generateEmail(duration: number = 30): Promise<EmailInfo> {
|
|
18
|
+
const response = await fetch(`${BASE_URL}/generate`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: DEFAULT_HEADERS,
|
|
21
|
+
body: JSON.stringify({ duration }),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`Failed to generate email: ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
|
|
30
|
+
if (!data.success) {
|
|
31
|
+
throw new Error('Failed to generate email');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
channel: CHANNEL,
|
|
36
|
+
email: data.email.address,
|
|
37
|
+
expiresAt: data.email.expiresAt,
|
|
38
|
+
createdAt: data.email.createdAt,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function getEmails(email: string): Promise<Email[]> {
|
|
43
|
+
const encodedEmail = encodeURIComponent(email);
|
|
44
|
+
const response = await fetch(`${BASE_URL}/emails/${encodedEmail}`, {
|
|
45
|
+
method: 'GET',
|
|
46
|
+
headers: DEFAULT_HEADERS,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(`Failed to get emails: ${response.status}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
|
|
55
|
+
if (!data.success) {
|
|
56
|
+
throw new Error('Failed to get emails');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const rawEmails = data.emails || [];
|
|
60
|
+
return rawEmails.map((raw: any) => normalizeEmail(raw, email));
|
|
61
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
|
-
export type Channel = 'tempmail' | 'linshi-email' | 'tempmail-lol' | 'chatgpt-org-uk';
|
|
2
|
-
|
|
3
|
-
export interface EmailInfo {
|
|
4
|
-
channel: Channel;
|
|
5
|
-
email: string;
|
|
6
|
-
token?: string;
|
|
7
|
-
expiresAt?: string | number;
|
|
8
|
-
createdAt?: string;
|
|
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
|
-
|
|
1
|
+
export type Channel = 'tempmail' | 'linshi-email' | 'tempmail-lol' | 'chatgpt-org-uk' | 'tempmail-la' | 'temp-mail-io' | 'awamail' | 'mail-tm' | 'dropmail';
|
|
2
|
+
|
|
3
|
+
export interface EmailInfo {
|
|
4
|
+
channel: Channel;
|
|
5
|
+
email: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
expiresAt?: string | number;
|
|
8
|
+
createdAt?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 标准化邮件附件
|
|
13
|
+
*/
|
|
14
|
+
export interface EmailAttachment {
|
|
15
|
+
filename: string;
|
|
16
|
+
size?: number;
|
|
17
|
+
contentType?: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 标准化邮件格式 - 所有提供商返回统一结构
|
|
23
|
+
*/
|
|
24
|
+
export interface Email {
|
|
25
|
+
/** 邮件唯一标识 */
|
|
26
|
+
id: string;
|
|
27
|
+
/** 发件人邮箱地址 */
|
|
28
|
+
from: string;
|
|
29
|
+
/** 收件人邮箱地址 */
|
|
30
|
+
to: string;
|
|
31
|
+
/** 邮件主题 */
|
|
32
|
+
subject: string;
|
|
33
|
+
/** 纯文本内容 */
|
|
34
|
+
text: string;
|
|
35
|
+
/** HTML 内容 */
|
|
36
|
+
html: string;
|
|
37
|
+
/** ISO 8601 格式的日期字符串 */
|
|
38
|
+
date: string;
|
|
39
|
+
/** 是否已读 */
|
|
40
|
+
isRead: boolean;
|
|
41
|
+
/** 附件列表 */
|
|
42
|
+
attachments: EmailAttachment[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface GetEmailsResult {
|
|
46
|
+
channel: Channel;
|
|
47
|
+
email: string;
|
|
48
|
+
emails: Email[];
|
|
49
|
+
success: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface GenerateEmailOptions {
|
|
53
|
+
channel?: Channel;
|
|
54
|
+
duration?: number;
|
|
55
|
+
domain?: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface GetEmailsOptions {
|
|
59
|
+
channel: Channel;
|
|
60
|
+
email: string;
|
|
61
|
+
token?: string;
|
|
62
|
+
}
|
package/test/example.ts
CHANGED
|
@@ -1,48 +1,63 @@
|
|
|
1
|
-
import { generateEmail, getEmails, TempEmailClient, Channel } from '../src';
|
|
2
|
-
|
|
3
|
-
async function testGenerateEmail() {
|
|
4
|
-
console.log('=== Test Generate Email ===\n');
|
|
5
|
-
|
|
6
|
-
// Test each channel
|
|
7
|
-
const channels: Channel[] = ['tempmail', 'linshi-email', 'tempmail-lol', 'chatgpt-org-uk'];
|
|
8
|
-
|
|
9
|
-
for (const channel of channels) {
|
|
10
|
-
try {
|
|
11
|
-
console.log(`Testing channel: ${channel}`);
|
|
12
|
-
const emailInfo = await generateEmail({ channel });
|
|
13
|
-
console.log(` Channel: ${emailInfo.channel}`);
|
|
14
|
-
console.log(` Email: ${emailInfo.email}`);
|
|
15
|
-
if (emailInfo.token) console.log(` Token: ${emailInfo.token}`);
|
|
16
|
-
if (emailInfo.expiresAt) console.log(` Expires: ${emailInfo.expiresAt}`);
|
|
17
|
-
console.log();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
console.log();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
import { generateEmail, getEmails, TempEmailClient, Channel } from '../src';
|
|
2
|
+
|
|
3
|
+
async function testGenerateEmail() {
|
|
4
|
+
console.log('=== Test Generate Email ===\n');
|
|
5
|
+
|
|
6
|
+
// Test each channel
|
|
7
|
+
const channels: Channel[] = ['tempmail', 'linshi-email', 'tempmail-lol', 'chatgpt-org-uk', 'tempmail-la', 'temp-mail-io', 'awamail', 'mail-tm', 'dropmail'];
|
|
8
|
+
|
|
9
|
+
for (const channel of channels) {
|
|
10
|
+
try {
|
|
11
|
+
console.log(`Testing channel: ${channel}`);
|
|
12
|
+
const emailInfo = await generateEmail({ channel });
|
|
13
|
+
console.log(` Channel: ${emailInfo.channel}`);
|
|
14
|
+
console.log(` Email: ${emailInfo.email}`);
|
|
15
|
+
if (emailInfo.token) console.log(` Token: ${emailInfo.token}`);
|
|
16
|
+
if (emailInfo.expiresAt) console.log(` Expires: ${emailInfo.expiresAt}`);
|
|
17
|
+
if (emailInfo.createdAt) console.log(` Created: ${emailInfo.createdAt}`);
|
|
18
|
+
console.log();
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error(` Error: ${error}`);
|
|
21
|
+
console.log();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function testGetEmails() {
|
|
27
|
+
console.log('=== Test Get Emails ===\n');
|
|
28
|
+
|
|
29
|
+
// Generate and check emails using client
|
|
30
|
+
const client = new TempEmailClient();
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const emailInfo = await client.generate({ channel: 'tempmail' });
|
|
34
|
+
console.log(`Generated: ${emailInfo.channel} - ${emailInfo.email}`);
|
|
35
|
+
|
|
36
|
+
const result = await client.getEmails();
|
|
37
|
+
console.log(`Emails count: ${result.emails.length}`);
|
|
38
|
+
|
|
39
|
+
// 展示标准化的邮件格式
|
|
40
|
+
for (const email of result.emails) {
|
|
41
|
+
console.log(` ID: ${email.id}`);
|
|
42
|
+
console.log(` From: ${email.from}`);
|
|
43
|
+
console.log(` To: ${email.to}`);
|
|
44
|
+
console.log(` Subject: ${email.subject}`);
|
|
45
|
+
console.log(` Date: ${email.date}`);
|
|
46
|
+
console.log(` IsRead: ${email.isRead}`);
|
|
47
|
+
console.log(` Text: ${email.text.substring(0, 100)}`);
|
|
48
|
+
console.log(` HTML: ${email.html.substring(0, 100)}`);
|
|
49
|
+
console.log(` Attachments: ${email.attachments.length}`);
|
|
50
|
+
console.log();
|
|
51
|
+
}
|
|
52
|
+
console.log();
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(`Error: ${error}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function main() {
|
|
59
|
+
await testGenerateEmail();
|
|
60
|
+
await testGetEmails();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
main().catch(console.error);
|
package/tsconfig.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["ES2020", "DOM"],
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noImplicitAny": true,
|
|
9
|
-
"strictNullChecks": true,
|
|
10
|
-
"noImplicitThis": true,
|
|
11
|
-
"alwaysStrict": true,
|
|
12
|
-
"noUnusedLocals": false,
|
|
13
|
-
"noUnusedParameters": false,
|
|
14
|
-
"noImplicitReturns": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": false,
|
|
16
|
-
"inlineSourceMap": true,
|
|
17
|
-
"inlineSources": true,
|
|
18
|
-
"experimentalDecorators": true,
|
|
19
|
-
"strictPropertyInitialization": false,
|
|
20
|
-
"outDir": "./dist",
|
|
21
|
-
"rootDir": "./src",
|
|
22
|
-
"skipLibCheck": true,
|
|
23
|
-
"esModuleInterop": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["src/**/*"],
|
|
26
|
-
"exclude": ["node_modules", "dist"]
|
|
27
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noImplicitAny": true,
|
|
9
|
+
"strictNullChecks": true,
|
|
10
|
+
"noImplicitThis": true,
|
|
11
|
+
"alwaysStrict": true,
|
|
12
|
+
"noUnusedLocals": false,
|
|
13
|
+
"noUnusedParameters": false,
|
|
14
|
+
"noImplicitReturns": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": false,
|
|
16
|
+
"inlineSourceMap": true,
|
|
17
|
+
"inlineSources": true,
|
|
18
|
+
"experimentalDecorators": true,
|
|
19
|
+
"strictPropertyInitialization": false,
|
|
20
|
+
"outDir": "./dist",
|
|
21
|
+
"rootDir": "./src",
|
|
22
|
+
"skipLibCheck": true,
|
|
23
|
+
"esModuleInterop": true
|
|
24
|
+
},
|
|
25
|
+
"include": ["src/**/*"],
|
|
26
|
+
"exclude": ["node_modules", "dist"]
|
|
27
|
+
}
|