-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
76 lines (69 loc) · 1.81 KB
/
script.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
const speakerEmailRecipients = [
];
const sponsorEmailRecipients = [
];
const primaryEmailsList = ["[email protected]"];
const urlParams = new URLSearchParams(window.location.search);
const state = urlParams.get("state");
const personName = urlParams.get("name");
const mailType = urlParams.get("type");
const mailDate = urlParams.get("maildate");
const pocEmail = urlParams.get("poc");
const currDate = new Date().toLocaleString();
const obj = {
state,
personName,
"Person Type": mailType,
mailDate,
"Responded Time": currDate,
"POC Email": pocEmail,
};
async function sendMail(toAll = false) {
if (!personName) return;
let toEmailList;
if (toAll) {
if (mailType.includes("sponsor")) {
toEmailList = sponsorEmailRecipients;
} else {
toEmailList = speakerEmailRecipients;
}
toEmailList.push(pocEmail);
} else {
toEmailList = primaryEmailsList;
}
const url =
"https://w2e9j471i2.execute-api.ap-south-1.amazonaws.com/dev/send-email";
const text = Object.entries(obj).reduce(
(acc, [key, value]) => acc + `${key}: ${value}\n`,
""
);
console.log(text);
console.log(toEmailList);
const params = {
subject: `${mailType} ${personName} - ${state}`,
content: `Email Response:\n${text}`,
toEmail: toEmailList,
};
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(params),
});
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
throw error;
}
}