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 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'index.js') 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); } }); -- cgit v1.2.3