Update Utils/sendEmail.js
This commit is contained in:
parent
f5371eb099
commit
e826dbc0ce
@ -21,45 +21,45 @@
|
||||
// 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
|
||||
});
|
||||
|
||||
// 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) => {
|
||||
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)
|
||||
}
|
||||
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
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Verify connection on startup
|
||||
transporter.verify(function(error) {
|
||||
if (error) {
|
||||
console.error("SMTP Connection Failed:", error);
|
||||
} else {
|
||||
console.log("SMTP Connection Ready");
|
||||
console.log('Email sent to:', options.to);
|
||||
return true;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Email failed:', error);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default sendEmail;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user