Update Utils/sendEmail.js
This commit is contained in:
parent
2997e49c9e
commit
69c7030d1e
@ -1,57 +1,25 @@
|
|||||||
// import nodeMailer from "nodemailer";
|
import nodeMailer from "nodemailer";
|
||||||
// import { createTransport } from "nodemailer";
|
import { createTransport } from "nodemailer";
|
||||||
|
|
||||||
// const transporter = createTransport({
|
const transporter = createTransport({
|
||||||
// host: process.env.SMPT_HOST,
|
host: process.env.SMPT_HOST,
|
||||||
// port: process.env.SMPT_PORT,
|
port: process.env.SMPT_PORT,
|
||||||
// // service: process.env.SMPT_SERVICE,
|
// 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,
|
|
||||||
auth: {
|
auth: {
|
||||||
user: "78ab42003@smtp-brevo.com",
|
user: process.env.SMPT_MAIL,
|
||||||
pass: "saTOdNcySftx2PXG"
|
pass: process.env.SMPT_PASSWORD,
|
||||||
},
|
},
|
||||||
tls: {
|
|
||||||
rejectUnauthorized: true // Enable for production
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default async function sendEmail(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 { success: true, messageId: info.messageId };
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Email failed:', error.message);
|
|
||||||
return { success: false, error: error.message };
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user