Update Utils/sendEmail.js
This commit is contained in:
parent
6d60198672
commit
642bc45b81
@ -19,39 +19,49 @@
|
|||||||
// });
|
// });
|
||||||
// };
|
// };
|
||||||
// export default sendEmail;
|
// export default sendEmail;
|
||||||
|
|
||||||
import { createTransport } from "nodemailer";
|
import { createTransport } from "nodemailer";
|
||||||
|
|
||||||
|
// 1. Hardcoded working configuration (from your successful test)
|
||||||
const transporter = createTransport({
|
const transporter = createTransport({
|
||||||
host: "smtp-relay.brevo.com", // Hardcoded to ensure it works
|
host: "smtp-relay.brevo.com",
|
||||||
port: 587,
|
port: 587,
|
||||||
secure: false, // Required for Brevo
|
secure: false,
|
||||||
auth: {
|
auth: {
|
||||||
user: "78ab42003@smtp-brevo.com", // Your exact working credentials
|
user: "78ab42003@smtp-brevo.com",
|
||||||
pass: "saTOdNcySftx2PXG"
|
pass: "saTOdNcySftx2PXG"
|
||||||
},
|
},
|
||||||
tls: {
|
tls: {
|
||||||
rejectUnauthorized: false // Disable temporarily for testing
|
ciphers: "SSLv3"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const sendEmail = async (options) => {
|
const sendEmail = async (options) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
transporter.sendMail({
|
transporter.sendMail({
|
||||||
...options,
|
...options,
|
||||||
from: options.from || `Cheminova <cheminova2004@gmail.com>` // Default sender
|
from: options.from || "Cheminova <cheminova2004@gmail.com>"
|
||||||
}, (error, info) => {
|
}, (error, info) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('Email error:', error);
|
console.log("Email send failed:", error);
|
||||||
reject(error);
|
reject(false); // Return false on error )
|
||||||
} else {
|
} else {
|
||||||
console.log('Email sent:', info.messageId);
|
console.log("Email sent:", info.messageId);
|
||||||
resolve(info);
|
resolve(true); // Return true on success
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 3. Connection verification
|
||||||
|
transporter.verify(function(error) {
|
||||||
|
if (error) {
|
||||||
|
console.error("SMTP Connection FAILED:", error);
|
||||||
|
} else {
|
||||||
|
console.log("SMTP Connection READY");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default sendEmail;
|
export default sendEmail;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user