-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (63 loc) · 1.8 KB
/
index.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
var SibApiV3Sdk = require("sib-api-v3-sdk");
var MAIL_LIST2 = require("./mail-list");
var EmailValidator = require("email-validator");
var dotenv = require("dotenv");
dotenv.config();
SibApiV3Sdk.ApiClient.instance.authentications["api-key"].apiKey =
process.env.API_KEY;
const fromMail = ""; // From email
const fromName = ""; // From Name
const subject = ""; // Mail Subject
const htmlContent = ``;
let MAILS = MAIL_LIST2.split(",");
// MAILS = MAILS.slice(0, 1000);
let MAILS = []; // Add the test mail here and comment line 15
MAILS = MAILS.filter((_mail) => EmailValidator.validate(_mail) === true);
let INVALID_EMAILS = MAILS.filter(
(_mail) => EmailValidator.validate(_mail) === false
);
console.log(MAILS);
let i = 0;
const sendBulkMail = async () => {
while (i <= MAILS.length) {
let MAILSTEMPLIST = MAILS.slice(i, i + 80);
let emails = [];
for (const email of MAILSTEMPLIST) {
emails.push({ email: email });
}
console.log(emails);
new SibApiV3Sdk.TransactionalEmailsApi()
.sendTransacEmail({
sender: { email: fromMail, name: fromName },
subject: subject,
htmlContent: htmlContent,
to: [
{
email: "[email protected]",
},
],
bcc: emails,
// attachment: [
// {
// url: "", // Upload the file to S3 (Public Access) and put the link
// name: "", // File name with extension
// },
// ],
})
.then(
function (data) {
console.log(data);
},
function (error) {
console.error(i + error);
}
);
i = i + 80;
await sleep(2000);
}
};
async function sleep(millis) {
return new Promise((resolve) => setTimeout(resolve, millis));
}
console.log(INVALID_EMAILS);
sendBulkMail();