const axios = require("axios"); const senderEmail = "ecoconnect@trial-ynrw7gy0qxol2k8e.mlsender.net"; const { getApiKey } = require("./apiKey"); async function sendEmail(recipientEmail, title, content) { try { const apiKey = await getApiKey("mailersend_api_key"); 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 ); } } const ecoconnectEmailLogoUrl = "https://onedrive.live.com/download?resid=FDC8D8692E9A43C0%21425747&authkey=%21ADT2uhKbMIG4iqw&width=1310&height=212"; async function sendPasswordResetEmail(email, firstName, resetToken) { let dateTimeNow = new Date().toLocaleString(); 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

This reset portal is opened on ${dateTimeNow}, for 60 minutes.

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 ); } async function sendThankYouEmail(recipientEmail, firstName) { let dateTimeNow = new Date().toLocaleString(); let emailContent = ` Homebill Contest Participation
ecoconnect logo

Dear ${firstName},

Thank you for participating in the Home Bill Contest.

We have carefully reviewed your submission and noticed some discrepancies:

To avoid disqualification, we kindly request you to submit a new entry with the correct documents.

Click the button below to access the contest page and resubmit your entry:

GO TO HOME BILL CONTEST

If you have any questions or need assistance, feel free to contact us.

Best regards,
ecoconnect administrators

ecoconnect logo

· Connecting neighbourhoods together

`; await sendEmail( recipientEmail, "Homebill Contest: Action Required", emailContent ); } module.exports = { sendPasswordResetEmail, sendThankYouEmail };