Skip to content

Commit 0e50602

Browse files
committed
fix: wip newsletter
1 parent be999fd commit 0e50602

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

api/src/controllers/mail.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,48 @@ router.post(
6666
})
6767
);
6868

69+
router.post("/subscribe", async (req, res) => {
70+
try {
71+
const { email } = req.body;
72+
73+
if (!email) {
74+
return res.status(400).json({ error: "Email is required" });
75+
}
76+
77+
const apiRes = await fetch("https://api.tipimail.com/v1/messages/send", {
78+
method: "POST",
79+
headers: {
80+
"X-Tipimail-ApiUser": TIPIMAIL_API_USER,
81+
"X-Tipimail-ApiKey": TIPIMAIL_API_KEY,
82+
"Content-Type": "application/json",
83+
},
84+
body: JSON.stringify({
85+
apiKey: TIPIMAIL_API_KEY,
86+
to: [
87+
{
88+
address: "tangi.mendes@selego.co",
89+
},
90+
],
91+
msg: {
92+
from: {
93+
address: "contact@jardinmental.fr",
94+
personalName: "Jardin Mental - Application",
95+
},
96+
subject: "New Newsletter Subscription",
97+
text: `New subscription to the newsletter from: ${email}`,
98+
},
99+
}),
100+
}).catch((err) => capture(err, { extra: { route: "POST /mail/subscribe", body: req.body } }));
101+
102+
if (apiRes?.ok) {
103+
return res.status(200).json({ message: "Subscription successful" });
104+
}
105+
106+
res.status(200).json({ ok: true, message: "Subscription successful" });
107+
} catch (error) {
108+
console.error("Newsletter subscription error:", error);
109+
res.status(500).json({ error: "Internal server error" });
110+
}
111+
});
112+
69113
module.exports = { router };

0 commit comments

Comments
 (0)