Spaces:
Build error

primestake / backend /src /utils /sendEmail.js
Enternalishere
Initial commit: Prime Stake Platform (Production Audit Fixes Applied)
dae886b
Raw History Blame Contribute Delete
1.53 kB
import nodemailer from "nodemailer";
export const sendEmail = async ({ to, subject, text, html }) => {
try {
// Check if SMTP credentials are provided
if (!process.env.SMTP_HOST || !process.env.SMTP_USER || !process.env.SMTP_PASS) {
console.log("==================================================");
console.log(`[MOCK EMAIL] To: ${to}`);
console.log(`[MOCK EMAIL] Subject: ${subject}`);
console.log(`[MOCK EMAIL] Body: ${text || html}`);
console.log("==================================================");
return;
}
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 587,
secure: false, // true for 465, false for other ports
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
const info = await transporter.sendMail({
from: process.env.SMTP_FROM || '"Prime Stake" <no-reply@primestake.com>',
to,
subject,
text,
html,
});
console.log("Message sent: %s", info.messageId);
} catch (error) {
console.error("Error sending email:", error);
// Fallback to console log if email fails
console.log("==================================================");
console.log(`[FALLBACK EMAIL] To: ${to}`);
console.log(`[FALLBACK EMAIL] Subject: ${subject}`);
console.log(`[FALLBACK EMAIL] Body: ${text || html}`);
console.log("==================================================");
}
};