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
import { fetch } from "https://esm.town/v/std/fetch";
import { emailWebhookMap } from "https://esm.town/v/neverstew/emailWebhookMap";
export async function valtownForwarder(e: {
from: string;
to: string[];
subject: string;
text: string;
html: string;
}) {
const destinations = emailWebhookMap[e.from];
if (!destinations || destinations.length === 0)
return;
await Promise.all(destinations.map((destination) => {
return new Promise((resolve) => {
const timeout = setTimeout(() => {
console.error(`Timed out for ${destination}`);
resolve(false);
}, 3000);
fetch(destination).then((x) => {
console.log(`Delivered to ${destination}`);
}).catch((x) => {
console.log(`Delivery failed to ${destination}`);
})
.finally(() => {
clearTimeout(timeout);
resolve(true);
});
});
}));
// console.email(e.text, "Emailed received at @neverstew.valtownForwarder!");
}
// Forked from @stevekrouse.testEmail2
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023