Update Utils/sendEmail.js
This commit is contained in:
parent
642bc45b81
commit
9cb4d8310b
@ -1,70 +1,27 @@
|
|||||||
// import nodeMailer from "nodemailer";
|
import nodeMailer from "nodemailer";
|
||||||
// import { createTransport } from "nodemailer";
|
|
||||||
|
|
||||||
// const transporter = createTransport({
|
|
||||||
// host: process.env.SMPT_HOST,
|
|
||||||
// port: process.env.SMPT_PORT,
|
|
||||||
// // service: process.env.SMPT_SERVICE,
|
|
||||||
// auth: {
|
|
||||||
// user: process.env.SMPT_MAIL,
|
|
||||||
// pass: process.env.SMPT_PASSWORD,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const sendEmail = async (options) => {
|
|
||||||
// await transporter.sendMail(options, function (error, info) {
|
|
||||||
// if (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
// 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",
|
host: process.env.SMPT_HOST,
|
||||||
port: 587,
|
port: process.env.SMPT_PORT,
|
||||||
secure: false,
|
// service: process.env.SMPT_SERVICE,
|
||||||
auth: {
|
auth: {
|
||||||
user: "78ab42003@smtp-brevo.com",
|
user: process.env.SMPT_MAIL,
|
||||||
pass: "saTOdNcySftx2PXG"
|
pass: process.env.SMPT_PASSWORD,
|
||||||
},
|
},
|
||||||
tls: {
|
|
||||||
ciphers: "SSLv3"
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const sendEmail = async (options) => {
|
const sendEmail = async (options) => {
|
||||||
return new Promise((resolve, reject) => {
|
await transporter.sendMail(options, function (error, info) {
|
||||||
transporter.sendMail({
|
|
||||||
...options,
|
|
||||||
from: options.from || "Cheminova <cheminova2004@gmail.com>"
|
|
||||||
}, (error, info) => {
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Email send failed:", error);
|
console.log(error);
|
||||||
reject(false); // Return false on error )
|
|
||||||
} else {
|
|
||||||
console.log("Email sent:", info.messageId);
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// import sgMail from '@sendgrid/mail';
|
// import sgMail from '@sendgrid/mail';
|
||||||
// sgMail.setApiKey(process.env.SENDGRID_API_KEY)
|
// sgMail.setApiKey(process.env.SENDGRID_API_KEY)
|
||||||
// // console.log(process.env.SENDGRID_API_KEY)
|
// // console.log(process.env.SENDGRID_API_KEY)
|
||||||
|
Loading…
Reference in New Issue
Block a user