-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
56 lines (46 loc) · 1.54 KB
/
test.js
1
2
3
4
5
6
7
8
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
const CHANCE = require('chance');
/**
* This is the event driven mailbox section
*/
const { TempMailBoxEventDriven } = require('./main');
const chance = new CHANCE();
// This will generate a random first name and then a random email.
const eventDrivenInbox = new TempMailBoxEventDriven(chance.first());
// Waiting for the email to be ready (recommended)
eventDrivenInbox.on('ready', () => {
console.log('Your event driven email inbox is ready!');
console.log(eventDrivenInbox);
});
eventDrivenInbox.on('new', (newEmails) => {
console.log('Received new Emails in event driven inbox');
console.table(newEmails);
});
eventDrivenInbox.on('error', (error) => {
console.error(`Error in event driven inbox ${error}`);
});
/**
* This is the regular temp-mail box section
*/
const { TempMailBox } = require('./main');
// It will create an address like "[email protected]"
const email1 = new TempMailBox('temp-email');
// Waiting for the email to be ready (recommended)
email1.ready((email, error) => {
if (!error) {
console.log(`Email address is ${email}`);
// Getting email list
email1.getEmails((emails, err) => {
if (!err) {
console.log('Email list :', emails);
} else console.error(err);
});
// Fetching email list every 1 second and log if there is a new email
setInterval(() => {
email1.getEmails((emails, err, change) => {
if (!err) {
if (change) console.log('New mail !', emails);
} else console.error(err);
});
}, 1000);
} else console.error(error);
});