aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail.js
blob: a146d128de9ab298b7cad020d562654b5cca6943 (plain) (blame)
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
import app from "$app";
import config from "$config";
import persist from "./persist";
const emails = persist("data/emails.json");

app.post("/email", async (req, res) => {
  try {
    let file = persist("data/emails.json");
    file.emails = [...file.emails, req.body];

    try {
      var postmark = await import("postmark");

      var client = new postmark.ServerClient(config.postmark);

      await client.sendEmail({
        From: "[email protected]",
        To: "[email protected]",
        Subject: req.body.subject || "Email Signup",
        HtmlBody: JSON.stringify(req.body),
        TextBody: JSON.stringify(req.body),
        MessageStream: "outbound"
      });

      res.send({ ok: true });
    } catch (e) {
      console.log("problem sending email", e);
      res.code(500).send(e.message);
    }
  } catch (e) {
    console.log(e);
    res.code(500).send(e.message);
  }
});