-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (32 loc) · 1.07 KB
/
app.js
File metadata and controls
39 lines (32 loc) · 1.07 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
// app.js
document.getElementById('email-form').addEventListener('submit', async (event) => {
event.preventDefault();
const to = document.getElementById('to').value;
const subject = document.getElementById('subject').value;
const body = document.getElementById('body').value;
const response = await fetch('/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ to, subject, text: body }),
});
const result = await response.text();
alert(result);
});
async function loadEmails() {
const response = await fetch('/receive');
const emails = await response.json();
const emailsDiv = document.getElementById('emails');
emailsDiv.innerHTML = '';
emails.forEach(email => {
const emailDiv = document.createElement('div');
emailDiv.classList.add('email');
emailDiv.innerHTML = `
<h3>${email.subject}</h3>
<p>${email.text}</p>
`;
emailsDiv.appendChild(emailDiv);
});
}
loadEmails();