-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
93 lines (86 loc) · 3.54 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//---------validating emails--------------
let upload = document.getElementById('upload');
upload.addEventListener('change', () => {
let fr = new FileReader();
fr.readAsText(upload.files[0]);
fr.onload = function () {
let Arr = fr.result.split(/\r?\n|\n/).map(e => {
return e.split(',');
});
window.valNo = 0;
let invalNo = 0;
window.valMail = [];
Arr.forEach(e => {
let em = String(e);
let m = e.map(e => {
return `<td>${e}</td>`; // td = table data
})
let creEle = document.createElement("tr"); //tr = table row
creEle.innerHTML = m;
if (em != "") { // so that blank row will not be printed as well as counted
// if (em.indexOf('@') != 0) {
// document.querySelector("table#val").appendChild(creEle);
// return false;
// }
if (em.charAt(em.length - 4) == '.') {
document.querySelector("table#val").appendChild(creEle);
window.valMail.push(em);
window.valNo = window.valNo + 1;
return false;
}
else if (em.charAt(em.length - 3) == '.') {
document.querySelector("table#val").appendChild(creEle);
window.valMail.push(em);
window.valNo = window.valNo + 1;
return false;
}
else {
document.querySelector("table#inval").appendChild(creEle);
invalNo = invalNo + 1;
// console.log(creEle);
return false;
}
}
});
document.querySelector('#valCount').innerHTML = window.valNo;
document.querySelector('#invalCount').innerHTML = invalNo;
};
});
//-----------sending emails---------------
/*function sendEmail() {
Email.send({
Host: "smtp.elasticemail.com",
Username: "[email protected]",
Password: "AB21408E930F8DF83D222DA6D0203493DE2E",
To: "",
From: "[email protected]",
Subject: document.querySelector('#subject').value,
Body: document.getElementById('msg').value
}).then(
message => alert(window.valNo + " mails has been sent successfully, press " + message + " to continue.")
);
console.log(document.getElementById('msg').value);
console.log(document.getElementById('msg').innerHTML);
console.log(document.getElementById('msg').innerText);
}*/
function sendEmail() {
let validEmails = window.valMail;
// Iterate over each valid email
validEmails.forEach(email => {
Email.send({
Host: "smtp.elasticemail.com",
Username: "[email protected]",
Password: "AB21408E930F8DF83D222DA6D0203493DE2E",
To: email, // Send to the current valid email
From: "[email protected]",
Subject: document.querySelector('#subject').value,
Body: document.getElementById('msg').value
}).then(
message => alert(validEmails.length + " valid emails have been sent, press" + message + " to continue.")
);
});
// Display alert for the number of emails sent
console.log(document.getElementById('msg').value);
console.log(document.getElementById('msg').innerHTML);
console.log(document.getElementById('msg').innerText);
}