-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.ts
53 lines (49 loc) · 1.48 KB
/
index.ts
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
interface Env {
[key: string]: string;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
// console.log(env.DKIM_PRIVATE_KEY);
let send_request = new Request("https://api.mailchannels.net/tx/v1/send", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
personalizations: [
{
to: [
{
email: "", // add your to email here
},
],
dkim_domain: "", // add your domain
dkim_selector: "mailchannels",
dkim_private_key: env.DKIM_PRIVATE_KEY,
},
],
from: {
email: "", // add your from email here
},
subject: "Subject",
content: [
{
type: "text/plain",
value: "message",
},
],
}),
});
let respContent = "";
// only send the mail on "POST", to avoid spiders, etc.
if (request.method == "POST") {
const resp = await fetch(send_request);
const respText = await resp.text();
respContent = resp.status + " " + resp.statusText + "\n\n" + respText;
}
let htmlContent = `<html><head></head><body><p>Click to send message: <form method="post"><input type="submit" value="Send"/></form></p><pre>${respContent}</pre></body></html>`;
return new Response(htmlContent, {
headers: { "content-type": "text/html" },
});
},
};