dx-mail 1.0.1 โ†’ 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 (4) hide show
  1. package/README.md +602 -0
  2. package/a.js +1 -1
  3. package/index.js +1 -1
  4. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,602 @@
1
+ # ๐Ÿ“ฌ DX Mail
2
+
3
+ ![npm](https://img.shields.io/npm/v/dx-mail)
4
+ ![downloads](https://img.shields.io/npm/dm/dx-mail)
5
+ ![license](https://img.shields.io/npm/l/dx-mail)
6
+
7
+ Fast temporary email client with realtime inbox updates.
8
+
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
+
11
+ Perfect for Telegram bots, WhatsApp bots, web inboxes, OTP listeners, verification flows, testing tools, and custom mail automation.
12
+
13
+ ---
14
+
15
+ ## โœจ Features
16
+
17
+ - ๐Ÿš€ Create random temporary email addresses
18
+ - ๐Ÿท๏ธ Create custom email addresses
19
+ - โšก Realtime inbox updates using WebSocket
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
26
+
27
+ ---
28
+
29
+ ## ๐Ÿ“ฆ Installation
30
+
31
+ ```bash
32
+ npm install dx-mail
33
+ ```
34
+
35
+ ---
36
+
37
+ ## ๐Ÿš€ Quick Start
38
+
39
+ ```js
40
+ const dxMail = require("dx-mail");
41
+
42
+ const app = dxMail({
43
+ baseUrl: "https://your-server.com",
44
+ token: "dxm_your_api_key"
45
+ });
46
+
47
+ async function main() {
48
+ const res = await app.createMail();
49
+
50
+ console.log("Your email address:");
51
+ console.log(res.inbox.address);
52
+ }
53
+
54
+ main().catch(console.error);
55
+ ```
56
+
57
+ Example output:
58
+
59
+ ```txt
60
+ m7fa8d3c21a@yourdomain.com
61
+ ```
62
+
63
+ ---
64
+
65
+ ## ๐Ÿ” Authentication
66
+
67
+ You can pass your API key directly when creating the client.
68
+
69
+ ```js
70
+ const dxMail = require("dx-mail");
71
+
72
+ const app = dxMail({
73
+ baseUrl: "https://your-server.com",
74
+ token: "dxm_your_api_key"
75
+ });
76
+ ```
77
+
78
+ Or use the chained style.
79
+
80
+ ```js
81
+ const dxMail = require("dx-mail");
82
+
83
+ const app = dxMail();
84
+
85
+ app.setBaseUrl("https://your-server.com");
86
+ app.auth("dxm_your_api_key");
87
+ ```
88
+
89
+ ---
90
+
91
+ ## ๐Ÿ“ฎ Create a Random Email
92
+
93
+ ```js
94
+ const res = await app.createMail();
95
+
96
+ console.log(res.inbox.address);
97
+ ```
98
+
99
+ Example:
100
+
101
+ ```txt
102
+ m9c81a7e231@yourdomain.com
103
+ ```
104
+
105
+ ---
106
+
107
+ ## ๐Ÿท๏ธ Create a Custom Email
108
+
109
+ ```js
110
+ const res = await app.createMail("test1");
111
+
112
+ console.log(res.inbox.address);
113
+ ```
114
+
115
+ Example:
116
+
117
+ ```txt
118
+ test1@yourdomain.com
119
+ ```
120
+
121
+ ---
122
+
123
+ ## ๐Ÿงต Callback Style
124
+
125
+ DX Mail supports both Promise and callback styles.
126
+
127
+ ```js
128
+ app.createMail("test1", (res) => {
129
+ console.log(res.inbox.address);
130
+ });
131
+ ```
132
+
133
+ ```js
134
+ app.listMail((res) => {
135
+ console.log(res.inboxes);
136
+ });
137
+ ```
138
+
139
+ ---
140
+
141
+ ## ๐Ÿ“š List All Emails
142
+
143
+ Get all inboxes owned by your API key.
144
+
145
+ ```js
146
+ const res = await app.listMail();
147
+
148
+ console.log(res.inboxes);
149
+ ```
150
+
151
+ Example response:
152
+
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
+ ```
169
+
170
+ ---
171
+
172
+ ## ๐Ÿ“ฅ Read Messages
173
+
174
+ ```js
175
+ const res = await app.getMail("test1");
176
+
177
+ console.log(res.messages);
178
+ ```
179
+
180
+ You can also use:
181
+
182
+ ```js
183
+ const res = await app.getMessages("test1");
184
+
185
+ console.log(res.messages);
186
+ ```
187
+
188
+ ---
189
+
190
+ ## โšก Watch an Inbox Realtime
191
+
192
+ Listen for incoming emails instantly.
193
+
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);
200
+ });
201
+ ```
202
+
203
+ When an email arrives, you will receive an event like this:
204
+
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
+ ```
225
+
226
+ ---
227
+
228
+ ## ๐Ÿ›‘ Stop Watching
229
+
230
+ `watchMail()` returns an unsubscribe function.
231
+
232
+ ```js
233
+ const stop = app.watchMail("test1", (event) => {
234
+ console.log(event.message.subject);
235
+ });
236
+
237
+ stop();
238
+ ```
239
+
240
+ ---
241
+
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
+ ```
254
+
255
+ ---
256
+
257
+ ## โณ Wait for One Email
258
+
259
+ Useful for OTP, verification links, or test automation.
260
+
261
+ ```js
262
+ const event = await app.waitMail("test1");
263
+
264
+ console.log(event.message.subject);
265
+ console.log(event.message.text);
266
+ ```
267
+
268
+ With timeout:
269
+
270
+ ```js
271
+ const event = await app.waitMail("test1", {
272
+ timeoutMs: 30000
273
+ });
274
+ ```
275
+
276
+ ---
277
+
278
+ ## ๐ŸŒ HTML Email Support
279
+
280
+ Many platforms send HTML emails. DX Mail supports both text and HTML bodies.
281
+
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
+ }
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
+ ```
350
+
351
+ ---
352
+
353
+ ## ๐Ÿ–ฅ๏ธ Web Inbox Example
354
+
355
+ ```js
356
+ const dxMail = require("dx-mail");
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
468
+ app.close();
469
+ ```
470
+
471
+ ---
472
+
473
+ ## ๐Ÿ“ฆ Response Shapes
474
+
475
+ ### Inbox
476
+
477
+ ```js
478
+ {
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",
495
+ from: "noreply@example.com",
496
+ subject: "Welcome",
497
+ text: "Hello!",
498
+ html: "<p>Hello!</p>",
499
+ attachments: [],
500
+ receivedAt: "2026-06-27T14:00:00.000Z",
501
+ createdAt: "2026-06-27T14:00:01.000Z"
502
+ }
503
+ ```
504
+
505
+ ---
506
+
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:
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
532
+ const dxMail = require("dx-mail");
533
+
534
+ const app = dxMail({
535
+ baseUrl: "https://your-server.com",
536
+ token: "dxm_your_api_key"
537
+ });
538
+
539
+ async function main() {
540
+ const created = await app.createMail("demo");
541
+
542
+ console.log("Email created:", created.inbox.address);
543
+
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
+ ```
557
+
558
+ ---
559
+
560
+ ## ๐Ÿ”’ Security Notes
561
+
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);
578
+ });
579
+ ```
580
+
581
+ ---
582
+
583
+ ## ๐Ÿ› ๏ธ Built For
584
+
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
593
+
594
+ ---
595
+
596
+ ## ๐Ÿ“„ License
597
+
598
+ MIT
599
+
600
+ ---
601
+
602
+ Made for fast inbox experiments, bot builders, and people who enjoy turning email into realtime little lightning bolts. โšก
package/a.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const mail = require("./index.js");
2
2
  const app = mail();
3
3
 
4
- app.setBaseUrl("https://mailsrv-1a31daad9cb8.herokuapp.com");
4
+ //app.setBaseUrl("https://mailsrv-1a31daad9cb8.herokuapp.com");
5
5
  app.auth("dxm_46a9ac05fd8230b856f6d4fb1e1f4c5af63f6b045cda4a48");
6
6
 
7
7
  app.createMail("anj", (res) => {
package/index.js CHANGED
@@ -43,7 +43,7 @@ class DxMailClient extends EventEmitter {
43
43
  this.baseUrl = cleanBaseUrl(
44
44
  options.baseUrl ||
45
45
  process.env.DX_MAIL_BASE_URL ||
46
- "http://localhost:3000"
46
+ "https://mailsrv-1a31daad9cb8.herokuapp.com"
47
47
  );
48
48
 
49
49
  this.token = options.token || process.env.DX_MAIL_TOKEN || null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dx-mail",
3
- "version": "1.0.1",
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": [