-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifyEmails.js
More file actions
70 lines (60 loc) · 2.19 KB
/
Copy pathverifyEmails.js
File metadata and controls
70 lines (60 loc) · 2.19 KB
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
57
58
59
60
61
62
63
64
65
var emailExistence = require('email-existence');
var kickbox = require('kickbox').client('650f1e3c040b4d1ad1fece86a51777792fc32c16d8b717939d8a22d9ad9c4614').kickbox();
var validEmailFound = false;
module.exports = function(peeps, emails, checkForEmails, callback){
var check = checkForEmails;
if ((check === true) && (validEmailFound === false)){
var insideEmail = emails;
var count = 0;
var emailObjectLength = 0;
Object.keys(insideEmail).forEach(function (key) {
emailObjectLength++;
var email = insideEmail[key];
console.log(email);
var validEmail = "";
emailExistence.check(email, function(err,res){
if (res === true){
validEmail = email;
console.log("valid email: "+validEmail);
next(peeps, validEmail, false, "npm");
//TODO: Add a "found by" log so we know which service is getting us results.
} else {
kickbox.verify(email, function (err, response) {
if (err != null){
kickbox = require('kickbox').client('fe1d51397ea4b5c1a564c15cb6888973183bbbffb73813470a3d566c8eabbc00').kickbox();
if (response != null){
if ((response.body.result === 'deliverable') && (response.body.success === 'true') && (response.body.sendex > .95)){
validEmail = email;
console.log("valid email: "+validEmail);
next(peeps, validEmail, false, "kickbox");
} else {
count++
if (count === emailObjectLength) {
next(peeps, validEmail, true);
}
};
} else {
count++
if (count === emailObjectLength) {
next(peeps, validEmail, true);
}
};
} else {
if ((response.body.result === 'deliverable') && (response.body.success === 'true') && (response.body.sendex > .95)){
validEmail = email;
console.log("valid email: "+validEmail);
next(peeps, validEmail, false, "kickbox");
}
}
})
}
})
})
} else next(peeps, "", true, "");
function next(peeps, validEmail, check, validatedBy){
console.log("next: "+peeps.name);
peeps.validatedBy = validatedBy;
peeps.validEmails = validEmail;
callback(peeps);
}
}