Update Utils/sendEmail.js

This commit is contained in:
gitadmin 2025-04-28 20:01:11 +00:00
parent cd86426605
commit f5371eb099

View File

@ -19,40 +19,49 @@
// });
// };
// export default sendEmail;
import { createTransport } from "nodemailer";
// 1. Transport configuration (identical to your working version)
const transporter = createTransport({
host: "smtp-relay.brevo.com", // Directly using working host
host: "smtp-relay.brevo.com", // Verified working host
port: 587,
secure: false, // Keep false for STARTTLS
secure: false, // True for 465, false for other ports
auth: {
user: "78ab42003@smtp-brevo.com", // Your working credentials
pass: "saTOdNcySftx2PXG" // Your working password
user: "78ab42003@smtp-brevo.com", // Your verified credentials
pass: "saTOdNcySftx2PXG" // Your verified password
},
// No special TLS settings to match original working version
tls: {
rejectUnauthorized: false // Disable temporarily for testing
}
});
// 2. EXACT original function signature
// Maintains EXACT same interface your handleReset expects
const sendEmail = async (options) => {
return new Promise((resolve) => { // Remove reject to match your original
return new Promise((resolve) => {
transporter.sendMail({
...options,
from: options.from || "Cheminova <cheminova2004@gmail.com>"
}, (error, info) => {
if (error) {
console.log(error); // Same as original
resolve(false); // Return false on error (original behavior)
console.log('Email error:', error);
resolve(false); // Return false on error (matches your original behavior)
} else {
resolve(true); // Return true on success (original behavior)
console.log('Email sent:', info.messageId);
resolve(true); // Return true on success (matches your original behavior)
}
});
});
};
export default sendEmail;
// Verify connection on startup
transporter.verify(function(error) {
if (error) {
console.error("SMTP Connection Failed:", error);
} else {
console.log("SMTP Connection Ready");
}
});
export default sendEmail;
// import sgMail from '@sendgrid/mail';