fix: add missing mail.js and dependencies to backend

This commit is contained in:
AI Bot
2026-08-12 10:27:15 +05:30
parent b36f830770
commit 5ad38241cb
3 changed files with 2853 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
const nodemailer = require('nodemailer');
require('dotenv').config();
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST || 'smtp.office365.com',
port: parseInt(process.env.SMTP_PORT || '587', 10),
secure: process.env.SMTP_SECURE === 'true', // true for 465, false for other ports (587 uses STARTTLS)
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
tls: {
ciphers: 'SSLv3', // sometimes required for Office365
rejectUnauthorized: false
}
});
/**
* Sends an email using the configured SMTP server.
* @param {string} to - Recipient email address
* @param {string} subject - Email subject
* @param {string} text - Plain text body
* @param {string} html - HTML body (optional)
* @returns {Promise<any>} Info object from nodemailer
*/
const sendMail = async (to, subject, text, html = '') => {
try {
const info = await transporter.sendMail({
from: process.env.SMTP_FROM,
to,
subject,
text,
html
});
console.log(`Email sent to ${to}: ${info.messageId}`);
return info;
} catch (error) {
console.error('Error sending email:', error);
throw error;
}
};
module.exports = {
sendMail,
transporter
};
+2805
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -9,9 +9,11 @@
"dependencies": { "dependencies": {
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"cors": "^2.8.5", "cors": "^2.8.5",
"dotenv": "^17.4.2",
"express": "^4.18.2", "express": "^4.18.2",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
"nodemailer": "^9.0.5",
"sqlite3": "^5.1.7", "sqlite3": "^5.1.7",
"uuid": "^9.0.1" "uuid": "^9.0.1"
} }