Update Utils/sendEmail.js

This commit is contained in:
gitadmin 2025-04-28 20:08:08 +00:00
parent e826dbc0ce
commit b0d479daaf

View File

@ -1,69 +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";
// Hardcoded working credentials from your Python 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: { 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');
}
}); });
const sendEmail = async (options) => { const sendEmail = async (options) => {
try { await transporter.sendMail(options, function (error, info) {
const info = await transporter.sendMail({ if (error) {
from: options.from || "Cheminova <cheminova2004@gmail.com>", console.log(error);
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; 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)