dx-mail 1.0.2 โ†’ 1.0.3

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.
Files changed (2) hide show
  1. package/README.md +433 -104
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,30 +4,39 @@
4
4
  ![downloads](https://img.shields.io/npm/dm/dx-mail)
5
5
  ![license](https://img.shields.io/npm/l/dx-mail)
6
6
 
7
- Fast temporary email client with realtime inbox updates powered by WebSocket.
7
+ Fast temporary email client with realtime inbox updates.
8
8
 
9
- Create temporary emails, receive messages instantly, and integrate easily with Telegram bots, WhatsApp bots, web dashboards, or Node.js applications.
9
+ DX Mail lets you create temporary email inboxes, listen for incoming messages instantly, and integrate them into bots, dashboards, automation tools, or Node.js apps.
10
10
 
11
- โœจ Features
11
+ Perfect for Telegram bots, WhatsApp bots, web inboxes, OTP listeners, verification flows, testing tools, and custom mail automation.
12
12
 
13
- - ๐Ÿš€ Create random or custom temporary email addresses
13
+ ---
14
+
15
+ ## โœจ Features
16
+
17
+ - ๐Ÿš€ Create random temporary email addresses
18
+ - ๐Ÿท๏ธ Create custom email addresses
14
19
  - โšก Realtime inbox updates using WebSocket
15
- - ๐Ÿ“ฅ Fetch message history
16
- - ๐Ÿค– Perfect for Telegram and WhatsApp bots
17
- - ๐ŸŒ Works for web inbox applications
18
- - ๐Ÿ”‘ API Key authentication
19
- - ๐Ÿ“ฆ Lightweight and easy to use
20
+ - ๐Ÿ“ฅ Read message history
21
+ - ๐ŸŒ Supports plain text and HTML emails
22
+ - ๐Ÿค– Works great with Telegram and WhatsApp bots
23
+ - ๐Ÿงฉ Simple API, similar feeling to Express-style clients
24
+ - ๐Ÿ”‘ API key authentication
25
+ - ๐Ÿ“ฆ Lightweight Node.js client
20
26
 
21
27
  ---
22
28
 
23
- Installation
29
+ ## ๐Ÿ“ฆ Installation
24
30
 
31
+ ```bash
25
32
  npm install dx-mail
33
+ ```
26
34
 
27
35
  ---
28
36
 
29
- Quick Start
37
+ ## ๐Ÿš€ Quick Start
30
38
 
39
+ ```js
31
40
  const dxMail = require("dx-mail");
32
41
 
33
42
  const app = dxMail({
@@ -38,198 +47,488 @@ const app = dxMail({
38
47
  async function main() {
39
48
  const res = await app.createMail();
40
49
 
41
- console.log("Email:");
50
+ console.log("Your email address:");
42
51
  console.log(res.inbox.address);
43
52
  }
44
53
 
45
- main();
54
+ main().catch(console.error);
55
+ ```
56
+
57
+ Example output:
58
+
59
+ ```txt
60
+ m7fa8d3c21a@yourdomain.com
61
+ ```
46
62
 
47
63
  ---
48
64
 
49
- Authentication
65
+ ## ๐Ÿ” Authentication
50
66
 
51
- Option 1
67
+ You can pass your API key directly when creating the client.
68
+
69
+ ```js
70
+ const dxMail = require("dx-mail");
52
71
 
53
72
  const app = dxMail({
54
73
  baseUrl: "https://your-server.com",
55
74
  token: "dxm_your_api_key"
56
75
  });
76
+ ```
57
77
 
58
- Option 2
78
+ Or use the chained style.
79
+
80
+ ```js
81
+ const dxMail = require("dx-mail");
59
82
 
60
83
  const app = dxMail();
61
84
 
62
85
  app.setBaseUrl("https://your-server.com");
63
86
  app.auth("dxm_your_api_key");
87
+ ```
64
88
 
65
89
  ---
66
90
 
67
- API
68
-
69
- createMail()
70
-
71
- Create a random email address.
91
+ ## ๐Ÿ“ฎ Create a Random Email
72
92
 
93
+ ```js
73
94
  const res = await app.createMail();
74
95
 
75
96
  console.log(res.inbox.address);
97
+ ```
76
98
 
77
99
  Example:
78
100
 
79
- m7fa8d3c21a@danxy.web.id
101
+ ```txt
102
+ m9c81a7e231@yourdomain.com
103
+ ```
80
104
 
81
105
  ---
82
106
 
83
- createMail(name)
84
-
85
- Create a custom email address.
107
+ ## ๐Ÿท๏ธ Create a Custom Email
86
108
 
87
- const res = await app.createMail("test");
109
+ ```js
110
+ const res = await app.createMail("test1");
88
111
 
89
112
  console.log(res.inbox.address);
113
+ ```
90
114
 
91
- Output:
115
+ Example:
92
116
 
93
- test@danxy.web.id
117
+ ```txt
118
+ test1@yourdomain.com
119
+ ```
94
120
 
95
121
  ---
96
122
 
97
- createMail(callback)
123
+ ## ๐Ÿงต Callback Style
98
124
 
99
- Callback style.
125
+ DX Mail supports both Promise and callback styles.
100
126
 
101
- app.createMail((res) => {
127
+ ```js
128
+ app.createMail("test1", (res) => {
102
129
  console.log(res.inbox.address);
103
130
  });
131
+ ```
104
132
 
105
- ---
106
-
107
- createMail(name, callback)
108
-
109
- app.createMail("test", (res) => {
110
- console.log(res.inbox.address);
133
+ ```js
134
+ app.listMail((res) => {
135
+ console.log(res.inboxes);
111
136
  });
137
+ ```
112
138
 
113
139
  ---
114
140
 
115
- listMail()
141
+ ## ๐Ÿ“š List All Emails
116
142
 
117
143
  Get all inboxes owned by your API key.
118
144
 
145
+ ```js
119
146
  const res = await app.listMail();
120
147
 
121
148
  console.log(res.inboxes);
149
+ ```
122
150
 
123
- Example:
151
+ Example response:
124
152
 
125
- [
126
- {
127
- id: "...",
128
- name: "test",
129
- address: "test@danxy.web.id"
130
- }
131
- ]
153
+ ```js
154
+ {
155
+ ok: true,
156
+ count: 2,
157
+ inboxes: [
158
+ {
159
+ id: "667f...",
160
+ name: "test1",
161
+ address: "test1@yourdomain.com",
162
+ domain: "yourdomain.com",
163
+ expiresAt: "2026-06-28T10:00:00.000Z",
164
+ createdAt: "2026-06-27T10:00:00.000Z"
165
+ }
166
+ ]
167
+ }
168
+ ```
132
169
 
133
170
  ---
134
171
 
135
- getMail(name)
172
+ ## ๐Ÿ“ฅ Read Messages
173
+
174
+ ```js
175
+ const res = await app.getMail("test1");
176
+
177
+ console.log(res.messages);
178
+ ```
136
179
 
137
- Get message history.
180
+ You can also use:
138
181
 
139
- const res = await app.getMail("test");
182
+ ```js
183
+ const res = await app.getMessages("test1");
140
184
 
141
185
  console.log(res.messages);
186
+ ```
142
187
 
143
188
  ---
144
189
 
145
- watchMail(name)
190
+ ## โšก Watch an Inbox Realtime
146
191
 
147
- Receive emails instantly.
192
+ Listen for incoming emails instantly.
148
193
 
149
- app.watchMail("test", (event) => {
150
- console.log(event.message.subject);
151
- console.log(event.message.text);
194
+ ```js
195
+ app.watchMail("test1", (event) => {
196
+ console.log("New email received!");
197
+ console.log("From:", event.message.from);
198
+ console.log("Subject:", event.message.subject);
199
+ console.log("Text:", event.message.text);
152
200
  });
201
+ ```
153
202
 
154
- Example:
203
+ When an email arrives, you will receive an event like this:
155
204
 
156
- ๐Ÿ“ฉ New Email
157
- Subject: Hello
158
- Text: Welcome to DX Mail
205
+ ```js
206
+ {
207
+ type: "mail.received",
208
+ inbox: {
209
+ id: "667f...",
210
+ name: "test1",
211
+ address: "test1@yourdomain.com"
212
+ },
213
+ message: {
214
+ id: "6680...",
215
+ to: "test1@yourdomain.com",
216
+ from: "noreply@example.com",
217
+ subject: "Welcome",
218
+ text: "Hello from DX Mail!",
219
+ html: "<p>Hello from DX Mail!</p>",
220
+ attachments: [],
221
+ receivedAt: "2026-06-27T14:00:00.000Z"
222
+ }
223
+ }
224
+ ```
159
225
 
160
226
  ---
161
227
 
162
- HTML Emails
228
+ ## ๐Ÿ›‘ Stop Watching
163
229
 
164
- DX Mail supports HTML emails.
230
+ `watchMail()` returns an unsubscribe function.
165
231
 
166
- app.watchMail("test", (event) => {
167
- console.log(event.message.html);
232
+ ```js
233
+ const stop = app.watchMail("test1", (event) => {
234
+ console.log(event.message.subject);
168
235
  });
169
236
 
170
- Useful for:
237
+ stop();
238
+ ```
239
+
240
+ ---
171
241
 
172
- - OpenAI verification emails
173
- - GitHub notifications
174
- - Discord verification emails
175
- - Banking emails
176
- - Newsletter emails
177
- - OTP services
242
+ ## ๐ŸŒ Watch All Inboxes
243
+
244
+ Listen to all inboxes owned by your API key.
245
+
246
+ ```js
247
+ const stop = app.watchAll((event) => {
248
+ console.log("Inbox:", event.inbox.address);
249
+ console.log("Subject:", event.message.subject);
250
+ });
251
+
252
+ stop();
253
+ ```
178
254
 
179
255
  ---
180
256
 
181
- waitMail(name)
257
+ ## โณ Wait for One Email
182
258
 
183
- Wait until a new email arrives.
259
+ Useful for OTP, verification links, or test automation.
184
260
 
185
- const event = await app.waitMail("test");
261
+ ```js
262
+ const event = await app.waitMail("test1");
186
263
 
187
264
  console.log(event.message.subject);
265
+ console.log(event.message.text);
266
+ ```
188
267
 
189
268
  With timeout:
190
269
 
191
- const event = await app.waitMail("test", {
270
+ ```js
271
+ const event = await app.waitMail("test1", {
192
272
  timeoutMs: 30000
193
273
  });
274
+ ```
194
275
 
195
276
  ---
196
277
 
197
- watchAll()
278
+ ## ๐ŸŒ HTML Email Support
198
279
 
199
- Watch all inboxes owned by the API key.
280
+ Many platforms send HTML emails. DX Mail supports both text and HTML bodies.
200
281
 
201
- app.watchAll((event) => {
202
- console.log(event.inbox.address);
203
- console.log(event.message.subject);
282
+ ```js
283
+ app.watchMail("test1", (event) => {
284
+ if (event.message.html) {
285
+ console.log("HTML email received:");
286
+ console.log(event.message.html);
287
+ } else {
288
+ console.log(event.message.text);
289
+ }
204
290
  });
291
+ ```
292
+
293
+ For web inboxes, sanitize HTML before rendering it to users.
294
+
295
+ ---
296
+
297
+ ## ๐Ÿค– Telegram Bot Example
298
+
299
+ ```js
300
+ const dxMail = require("dx-mail");
301
+
302
+ const app = dxMail({
303
+ baseUrl: "https://your-server.com",
304
+ token: "dxm_your_api_key"
305
+ });
306
+
307
+ async function createUserMail(ctx) {
308
+ const res = await app.createMail();
309
+
310
+ await ctx.reply(`Your temporary email:\n${res.inbox.address}`);
311
+
312
+ app.watchMail(res.inbox.name, async (event) => {
313
+ await ctx.reply(
314
+ `๐Ÿ“ฉ New email!\n\nFrom: ${event.message.from}\nSubject: ${event.message.subject}\n\n${event.message.text}`
315
+ );
316
+ });
317
+ }
318
+ ```
319
+
320
+ ---
321
+
322
+ ## ๐Ÿ’ฌ WhatsApp Bot Example
323
+
324
+ ```js
325
+ const dxMail = require("dx-mail");
326
+
327
+ const app = dxMail({
328
+ baseUrl: "https://your-server.com",
329
+ token: "dxm_your_api_key"
330
+ });
331
+
332
+ async function createWhatsAppMail(sock, jid) {
333
+ const res = await app.createMail();
334
+
335
+ await sock.sendMessage(jid, {
336
+ text: `Your temporary email:\n${res.inbox.address}`
337
+ });
338
+
339
+ app.watchMail(res.inbox.name, async (event) => {
340
+ await sock.sendMessage(jid, {
341
+ text:
342
+ `๐Ÿ“ฉ New email!\n\n` +
343
+ `From: ${event.message.from}\n` +
344
+ `Subject: ${event.message.subject}\n\n` +
345
+ `${event.message.text}`
346
+ });
347
+ });
348
+ }
349
+ ```
205
350
 
206
351
  ---
207
352
 
208
- close()
353
+ ## ๐Ÿ–ฅ๏ธ Web Inbox Example
209
354
 
210
- Close WebSocket connection.
355
+ ```js
356
+ const dxMail = require("dx-mail");
211
357
 
358
+ const app = dxMail({
359
+ baseUrl: "https://your-server.com",
360
+ token: "dxm_your_api_key"
361
+ });
362
+
363
+ app.watchMail("test1", (event) => {
364
+ renderMessage(event.message);
365
+ });
366
+
367
+ function renderMessage(message) {
368
+ console.log(message.subject);
369
+ console.log(message.text);
370
+ }
371
+ ```
372
+
373
+ ---
374
+
375
+ ## ๐Ÿง  API Reference
376
+
377
+ ### `dxMail(options)`
378
+
379
+ Create a new DX Mail client.
380
+
381
+ ```js
382
+ const app = dxMail({
383
+ baseUrl: "https://your-server.com",
384
+ token: "dxm_your_api_key"
385
+ });
386
+ ```
387
+
388
+ ### `app.auth(token)`
389
+
390
+ Set or update the API key.
391
+
392
+ ```js
393
+ app.auth("dxm_your_api_key");
394
+ ```
395
+
396
+ ### `app.setBaseUrl(url)`
397
+
398
+ Set the DX Mail server URL.
399
+
400
+ ```js
401
+ app.setBaseUrl("https://your-server.com");
402
+ ```
403
+
404
+ ### `app.createMail(name?)`
405
+
406
+ Create a temporary inbox.
407
+
408
+ ```js
409
+ await app.createMail();
410
+ await app.createMail("customname");
411
+ ```
412
+
413
+ ### `app.listMail()`
414
+
415
+ List all inboxes owned by the API key.
416
+
417
+ ```js
418
+ await app.listMail();
419
+ ```
420
+
421
+ ### `app.getMail(name)`
422
+
423
+ Get messages from an inbox.
424
+
425
+ ```js
426
+ await app.getMail("test1");
427
+ ```
428
+
429
+ ### `app.getMessages(name)`
430
+
431
+ Alias for `getMail()`.
432
+
433
+ ```js
434
+ await app.getMessages("test1");
435
+ ```
436
+
437
+ ### `app.watchMail(name, callback)`
438
+
439
+ Watch one inbox in realtime.
440
+
441
+ ```js
442
+ const stop = app.watchMail("test1", callback);
443
+ ```
444
+
445
+ ### `app.watchAll(callback)`
446
+
447
+ Watch all inboxes in realtime.
448
+
449
+ ```js
450
+ const stop = app.watchAll(callback);
451
+ ```
452
+
453
+ ### `app.waitMail(name, options?)`
454
+
455
+ Wait until one email arrives.
456
+
457
+ ```js
458
+ const event = await app.waitMail("test1", {
459
+ timeoutMs: 60000
460
+ });
461
+ ```
462
+
463
+ ### `app.close()`
464
+
465
+ Close the WebSocket connection.
466
+
467
+ ```js
212
468
  app.close();
469
+ ```
213
470
 
214
471
  ---
215
472
 
216
- Message Object
473
+ ## ๐Ÿ“ฆ Response Shapes
474
+
475
+ ### Inbox
217
476
 
477
+ ```js
218
478
  {
219
- id: "...",
220
- to: "test@danxy.web.id",
479
+ id: "667f...",
480
+ name: "test1",
481
+ address: "test1@yourdomain.com",
482
+ domain: "yourdomain.com",
483
+ expiresAt: "2026-06-28T10:00:00.000Z",
484
+ createdAt: "2026-06-27T10:00:00.000Z"
485
+ }
486
+ ```
487
+
488
+ ### Message
489
+
490
+ ```js
491
+ {
492
+ id: "6680...",
493
+ inboxId: "667f...",
494
+ to: "test1@yourdomain.com",
221
495
  from: "noreply@example.com",
222
- subject: "Hello",
223
- text: "Welcome!",
224
- html: "<h1>Welcome!</h1>",
496
+ subject: "Welcome",
497
+ text: "Hello!",
498
+ html: "<p>Hello!</p>",
225
499
  attachments: [],
226
- receivedAt: "2026-06-27T14:00:00.000Z"
500
+ receivedAt: "2026-06-27T14:00:00.000Z",
501
+ createdAt: "2026-06-27T14:00:01.000Z"
227
502
  }
503
+ ```
228
504
 
229
505
  ---
230
506
 
231
- Telegram Example
507
+ ## โš™๏ธ Environment Variables
508
+
509
+ You can also configure the client using environment variables.
510
+
511
+ ```bash
512
+ DX_MAIL_BASE_URL=https://your-server.com
513
+ DX_MAIL_TOKEN=dxm_your_api_key
514
+ ```
515
+
516
+ Then:
232
517
 
518
+ ```js
519
+ const dxMail = require("dx-mail");
520
+
521
+ const app = dxMail();
522
+
523
+ const res = await app.createMail();
524
+ console.log(res.inbox.address);
525
+ ```
526
+
527
+ ---
528
+
529
+ ## ๐Ÿงช Full Example
530
+
531
+ ```js
233
532
  const dxMail = require("dx-mail");
234
533
 
235
534
  const app = dxMail({
@@ -237,37 +536,67 @@ const app = dxMail({
237
536
  token: "dxm_your_api_key"
238
537
  });
239
538
 
240
- const inbox = await app.createMail();
539
+ async function main() {
540
+ const created = await app.createMail("demo");
541
+
542
+ console.log("Email created:", created.inbox.address);
241
543
 
242
- app.watchMail(inbox.inbox.name, (event) => {
243
- bot.telegram.sendMessage(
244
- chatId,
245
- `๐Ÿ“ฉ ${event.message.subject}\n\n${event.message.text}`
246
- );
247
- });
544
+ app.watchMail("demo", (event) => {
545
+ console.log("\n๐Ÿ“ฉ New email!");
546
+ console.log("From:", event.message.from);
547
+ console.log("Subject:", event.message.subject);
548
+ console.log("Text:", event.message.text);
549
+ console.log("HTML:", event.message.html ? "yes" : "no");
550
+ });
551
+
552
+ console.log("Waiting for emails...");
553
+ }
554
+
555
+ main().catch(console.error);
556
+ ```
248
557
 
249
558
  ---
250
559
 
251
- Web Dashboard Example
560
+ ## ๐Ÿ”’ Security Notes
252
561
 
253
- app.watchMail("test", (event) => {
254
- renderMessage(event.message);
562
+ - Do not expose your API key in public frontend apps.
563
+ - Use server-side bots or backend services when possible.
564
+ - Sanitize HTML before rendering emails in a browser.
565
+ - Rotate API keys if they are leaked.
566
+ - Do not commit `.env` files to GitHub.
567
+
568
+ ---
569
+
570
+ ## ๐Ÿงน Cleanup
571
+
572
+ Close the connection when your app shuts down.
573
+
574
+ ```js
575
+ process.on("SIGINT", () => {
576
+ app.close();
577
+ process.exit(0);
255
578
  });
579
+ ```
256
580
 
257
581
  ---
258
582
 
259
- Requirements
583
+ ## ๐Ÿ› ๏ธ Built For
260
584
 
261
- - Node.js 18+
262
- - DX Mail Server
263
- - Valid API Key
585
+ - Temporary email systems
586
+ - OTP listeners
587
+ - Verification email capture
588
+ - Telegram bots
589
+ - WhatsApp bots
590
+ - Web inbox dashboards
591
+ - Automation scripts
592
+ - Developer testing tools
264
593
 
265
594
  ---
266
595
 
267
- License
596
+ ## ๐Ÿ“„ License
268
597
 
269
598
  MIT
270
599
 
271
600
  ---
272
601
 
273
- Made with โค๏ธ for developers who need fast temporary emails and realtime inbox updates.
602
+ Made for fast inbox experiments, bot builders, and people who enjoy turning email into realtime little lightning bolts. โšก
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dx-mail",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "DX Mail client for temp mail API and realtime inbox watcher",
5
5
  "main": "index.js",
6
6
  "keywords": [