Unlisted
Script
Readme

Now deprecated

This iswas a lightweight wrapper around SendGrid. It iswas the API complement to @std.email

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
import process from "node:process";
import { pros } from "https://esm.town/v/std/pros";
import { verifyAPIAuth } from "https://esm.town/v/stevekrouse/verifyAPIAuth?v=13";
export const emailAPI = async (
{ subject, from, to, cc, bcc, text, html, replyTo }: {
to: IAddress[];
from: IAddress;
cc?: IAddress[];
bcc?: IAddress[];
subject: string;
replyTo?: IAddress;
html?: string;
text?: string;
},
auth,
) => {
let { handle } = await verifyAPIAuth(auth);
if (!handle)
return "Could not verify auth";
if (!pros.includes(handle))
return "Email only for pro users";
const regex = new RegExp(`^${handle}\.[A-Za-z0-9_]+@valtown\.email$`);
if (!regex.test(from.email))
return `From email not valid, handle: ${handle}, email: ${from.email}`;
const { sendSimpleMail } = await import(
"https://deno.land/x/sendgrid/mod.ts"
);
console.email(null, `${handle} sent ${subject} to ${to?.at(0)?.email}`);
let response = await sendSimpleMail({
subject,
to,
from: from,
replyTo,
content: [
text && { type: "text/plain", value: text },
html && { type: "text/html", value: html },
].filter((c) => c),
}, {
apiKey: process.env.sendgrid,
});
let safeResponse = JSON.stringify(response).replaceAll(
process.env.sendgrid,
"XXXXXXXX",
);
return JSON.parse(safeResponse);
};
interface IAddress {
email: string;
name?: string;
}
// todo
// api key
// rate limit
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