import nodemailer from "nodemailer"; import { config } from "../config/env"; import { getSystemSettings } from "./system-settings"; const transporter = nodemailer.createTransport({ sendmail: true, newline: "unix", path: "/usr/sbin/sendmail", }); export async function sendMail( to: string, subject: string, html: string, ): Promise { const settings = await getSystemSettings(); const from = settings.smtp_from || config.email.smtpFrom || config.email.contactFrom || "noreply@example.com"; const fromName = settings.smtp_from_name || config.email.smtpFromName || "System"; try { await transporter.sendMail({ from: { name: fromName, address: from }, to, subject, html, }); return true; } catch (err) { console.error(`Mailer error: failed to send to ${to}:`, err); return false; } }