diff --git a/Utils/sendEmail.js b/Utils/sendEmail.js index 14ec40a..e3d8d7d 100644 --- a/Utils/sendEmail.js +++ b/Utils/sendEmail.js @@ -1,57 +1,25 @@ -// import nodeMailer from "nodemailer"; -// import { createTransport } 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 nodemailer from 'nodemailer'; - -const transporter = nodemailer.createTransport({ - host: "smtp-relay.brevo.com", - port: 587, - secure: false, +const transporter = createTransport({ + host: process.env.SMPT_HOST, + port: process.env.SMPT_PORT, + // service: process.env.SMPT_SERVICE, auth: { - user: "78ab42003@smtp-brevo.com", - pass: "saTOdNcySftx2PXG" + user: process.env.SMPT_MAIL, + pass: process.env.SMPT_PASSWORD, }, - tls: { - rejectUnauthorized: true // Enable for production - } }); -export default async function sendEmail(options) { - try { - const info = await transporter.sendMail({ - from: options.from || `Cheminova `, - 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 { success: true, messageId: info.messageId }; - - } catch (error) { - console.error('Email failed:', error.message); - return { success: false, error: error.message }; - } -} +const sendEmail = async (options) => { + await transporter.sendMail(options, function (error, info) { + if (error) { + console.log(error); + } + }); +}; +export default sendEmail; + // import sgMail from '@sendgrid/mail'; // sgMail.setApiKey(process.env.SENDGRID_API_KEY)