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,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 <cheminova2004@gmail.com>"
}, (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 <cheminova2004@gmail.com>",
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;