dx-mail 1.0.2 → 1.0.4

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