From e826dbc0ce86ebb73250fa37734a1459894f4c52 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 28 Apr 2025 20:03:58 +0000 Subject: [PATCH] Update Utils/sendEmail.js --- Utils/sendEmail.js | 58 +++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/Utils/sendEmail.js b/Utils/sendEmail.js index 61e5315..2769506 100644 --- a/Utils/sendEmail.js +++ b/Utils/sendEmail.js @@ -21,46 +21,46 @@ // export default sendEmail; import { createTransport } from "nodemailer"; +// Hardcoded working credentials from your Python test const transporter = createTransport({ - host: "smtp-relay.brevo.com", // Verified working host + host: "smtp-relay.brevo.com", port: 587, - secure: false, // True for 465, false for other ports + secure: false, auth: { - user: "78ab42003@smtp-brevo.com", // Your verified credentials - pass: "saTOdNcySftx2PXG" // Your verified password + user: "78ab42003@smtp-brevo.com", + pass: "saTOdNcySftx2PXG" }, - tls: { - rejectUnauthorized: false // Disable temporarily for testing - } + tls: { rejectUnauthorized: false } // Disable for testing }); -// Maintains EXACT same interface your handleReset expects -const sendEmail = async (options) => { - return new Promise((resolve) => { - transporter.sendMail({ - ...options, - from: options.from || "Cheminova " - }, (error, info) => { - if (error) { - console.log('Email error:', error); - resolve(false); // Return false on error (matches your original behavior) - } else { - console.log('Email sent:', info.messageId); - resolve(true); // Return true on success (matches your original behavior) - } - }); - }); -}; - -// Verify connection on startup -transporter.verify(function(error) { +// Debug connection on startup +transporter.verify((error) => { if (error) { - console.error("SMTP Connection Failed:", error); + console.error('SMTP Connection Failed:', error); } else { - console.log("SMTP Connection Ready"); + console.log('SMTP Connection Verified'); } }); +const sendEmail = async (options) => { + try { + const info = await transporter.sendMail({ + from: options.from || "Cheminova ", + to: options.to, + subject: options.subject, + html: options.html, + text: options.text || options.html.replace(/<[^>]*>/g, '') // Auto plaintext + }); + + console.log('Email sent to:', options.to); + return true; + + } catch (error) { + console.error('Email failed:', error); + return false; + } +}; + export default sendEmail;