const axios = require("axios"); const senderEmail = "ecoconnect@trial-ynrw7gy0qxol2k8e.mlsender.net"; async function getApiKey() { try { const response = await axios.get( "http://mommy.rya-orfe.ts.net:8069/mailersend_api_key" ); return response.data; } catch (error) { console.error("Error retrieving API key:", error); throw error; } } async function sendEmail(recipientEmail, title, content) { try { const apiKey = await getApiKey(); const response = await axios.post( "https://api.mailersend.com/v1/email", { from: { email: senderEmail, }, to: [ { email: recipientEmail, }, ], subject: title, text: content, html: content, }, { headers: { "Content-Type": "application/json", "X-Requested-With": "XMLHttpRequest", Authorization: `Bearer ${apiKey}`, }, } ); console.log("Email sent successfully:", response.data); } catch (error) { console.error( "Error sending email:", error.response ? error.response.data : error.message ); } } async function sendPasswordResetEmail(email, firstName) { let emailContent = ` ecoconnect Reset Password
ecoconnect logo

Greetings, ${firstName}!

We have received your request to reset the password.
Click the button below to do so.

RESET PASSWORD

If you have not made a request to reset the password, feel free to ignore this email.

Best regards,
ecoconnect administrators

ecoconnect logo

ยท Connecting neighbourhoods together

`; await sendEmail( email, "[Password Reset] Reset your password for ecoconnect", emailContent ); popToast(); } module.exports = { sendPasswordResetEmail };