1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { authenticateEmailKey } from "https://esm.town/v/chet/EmailKeys";
import { ValTupleStorage } from "https://esm.town/v/chet/ValTupleStorage";
import { email } from "https://esm.town/v/std/email?v=11";
export default async function(req: Request): Promise<Response> {
const searchParams = new URL(req.url).searchParams;
const { key, subject, text } = Object.fromEntries(searchParams.entries());
if (!key) return Response.json({ error: "Missing key query param." });
// if (!subject) return Response.json({ error: "Missing subject query param." });
// if (!text) return Response.json({ error: "Missing text query param." });
const error = await authenticateEmailKey(key);
if (error) return Response.json({ error });
await email({ subject, text });
return Response.json({ message: "Email sent!" });
}
1
Next