diff options
Diffstat (limited to 'index.js')
| -rw-r--r-- | index.js | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -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"); + // Require: + var postmark = require("postmark"); - // Send an email: - var client = new postmark.ServerClient( - config.postmark - ); + // Send an email: + var client = new postmark.ServerClient(config.postmark); - client.sendEmail({ - From: "[email protected]", - To: "[email protected]", - Subject: "Email Signup", - HtmlBody: JSON.stringify(req.body), - TextBody: JSON.stringify(req.body), - MessageStream: "outbound" - }); - } catch(e) { + 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); } }); |
