Update Utils/sendEmail.js

This commit is contained in:
gitadmin 2025-04-28 20:03:58 +00:00
parent f5371eb099
commit e826dbc0ce

View File

@ -21,45 +21,45 @@
// export default sendEmail; // export default sendEmail;
import { createTransport } from "nodemailer"; import { createTransport } from "nodemailer";
// Hardcoded working credentials from your Python test
const transporter = createTransport({ const transporter = createTransport({
host: "smtp-relay.brevo.com", // Verified working host host: "smtp-relay.brevo.com",
port: 587, port: 587,
secure: false, // True for 465, false for other ports secure: false,
auth: { auth: {
user: "78ab42003@smtp-brevo.com", // Your verified credentials user: "78ab42003@smtp-brevo.com",
pass: "saTOdNcySftx2PXG" // Your verified password pass: "saTOdNcySftx2PXG"
}, },
tls: { tls: { rejectUnauthorized: false } // Disable for testing
rejectUnauthorized: false // Disable temporarily for testing });
// Debug connection on startup
transporter.verify((error) => {
if (error) {
console.error('SMTP Connection Failed:', error);
} else {
console.log('SMTP Connection Verified');
} }
}); });
// Maintains EXACT same interface your handleReset expects
const sendEmail = async (options) => { const sendEmail = async (options) => {
return new Promise((resolve) => { try {
transporter.sendMail({ const info = await transporter.sendMail({
...options, from: options.from || "Cheminova <cheminova2004@gmail.com>",
from: options.from || "Cheminova <cheminova2004@gmail.com>" to: options.to,
}, (error, info) => { subject: options.subject,
if (error) { html: options.html,
console.log('Email error:', error); text: options.text || options.html.replace(/<[^>]*>/g, '') // Auto plaintext
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 console.log('Email sent to:', options.to);
transporter.verify(function(error) { return true;
if (error) {
console.error("SMTP Connection Failed:", error); } catch (error) {
} else { console.error('Email failed:', error);
console.log("SMTP Connection Ready"); return false;
} }
}); };
export default sendEmail; export default sendEmail;