Update Utils/sendEmail.js
This commit is contained in:
parent
cd86426605
commit
f5371eb099
@ -19,40 +19,49 @@
|
|||||||
// });
|
// });
|
||||||
// };
|
// };
|
||||||
// export default sendEmail;
|
// export default sendEmail;
|
||||||
|
|
||||||
import { createTransport } from "nodemailer";
|
import { createTransport } from "nodemailer";
|
||||||
|
|
||||||
// 1. Transport configuration (identical to your working version)
|
|
||||||
const transporter = createTransport({
|
const transporter = createTransport({
|
||||||
host: "smtp-relay.brevo.com", // Directly using working host
|
host: "smtp-relay.brevo.com", // Verified working host
|
||||||
port: 587,
|
port: 587,
|
||||||
secure: false, // Keep false for STARTTLS
|
secure: false, // True for 465, false for other ports
|
||||||
auth: {
|
auth: {
|
||||||
user: "78ab42003@smtp-brevo.com", // Your working credentials
|
user: "78ab42003@smtp-brevo.com", // Your verified credentials
|
||||||
pass: "saTOdNcySftx2PXG" // Your working password
|
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) => {
|
const sendEmail = async (options) => {
|
||||||
return new Promise((resolve) => { // Remove reject to match your original
|
return new Promise((resolve) => {
|
||||||
transporter.sendMail({
|
transporter.sendMail({
|
||||||
...options,
|
...options,
|
||||||
from: options.from || "Cheminova <cheminova2004@gmail.com>"
|
from: options.from || "Cheminova <cheminova2004@gmail.com>"
|
||||||
}, (error, info) => {
|
}, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log(error); // Same as original
|
console.log('Email error:', error);
|
||||||
resolve(false); // Return false on error (original behavior)
|
resolve(false); // Return false on error (matches your original behavior)
|
||||||
} else {
|
} 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';
|
// import sgMail from '@sendgrid/mail';
|
||||||
|
Loading…
Reference in New Issue
Block a user