From d277cd3e95c1e2c53f49ac965051e77319a0d8d5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 22 Jun 2022 21:00:44 -0700 Subject: update email endpoint --- index.js | 39 ++++++++++++++++++++------------------- pnpm-lock.yaml | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 3e0cd436..1c1b171c 100644 --- a/index.js +++ b/index.js @@ -108,30 +108,31 @@ app.post("/email", async (req, res) => { try { let file = persist("data/emails.json"); file.emails = [...file.emails, req.body]; - res.send({ ok: true }); try { - // Require: - var postmark = require("postmark"); - - // Send an email: - var client = new postmark.ServerClient( - config.postmark - ); - - client.sendEmail({ - From: "adam@coinos.io", - To: "adam@coinos.io", - Subject: "Email Signup", - HtmlBody: JSON.stringify(req.body), - TextBody: JSON.stringify(req.body), - MessageStream: "outbound" - }); - } catch(e) { + // Require: + var postmark = require("postmark"); + + // Send an email: + var client = new postmark.ServerClient(config.postmark); + + await client.sendEmail({ + From: "support@coinos.io", + To: "support@coinos.io", + 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); } }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd05d57d..aa7ab550 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1049,7 +1049,7 @@ packages: dev: false /bs58/4.0.1: - resolution: {integrity: sha1-vhYedsNU9veIrkBx9j806MTwpCo=} + resolution: {integrity: sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==} dependencies: base-x: 3.0.8 dev: false -- cgit v1.2.3