first commit

This commit is contained in:
tusuii
2026-02-19 17:25:38 +05:30
commit 09ea6d4efb
72 changed files with 24296 additions and 0 deletions

34
src/utils/mailer.js Normal file
View File

@@ -0,0 +1,34 @@
const nodemailer = require('nodemailer');
const ejs = require('ejs');
const path = require('path');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
const sendEmail = async (to, subject, templateName, templateData) => {
// Render EJS template
const templatePath = path.join(__dirname, '../views/emails', `${templateName}.ejs`);
const html = await ejs.renderFile(templatePath, templateData);
const mailOptions = {
from: `"VC E-Commerce" <${process.env.EMAIL_USER}>`,
to,
subject,
html,
};
try {
await transporter.sendMail(mailOptions);
console.log('Email sent to', to);
} catch (err) {
console.error('Error sending email', err);
throw new Error('Failed to send email');
}
};
module.exports = sendEmail;