import nodemailer from "nodemailer"; let cached: nodemailer.Transporter | null = null; /** SMTP transporter for the existing ANOUMA mail system — no external newsletter service. */ export function getMailTransport(): nodemailer.Transporter { if (cached) return cached; const { SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD } = process.env; if (!SMTP_HOST || !SMTP_PORT || !SMTP_USER || !SMTP_PASSWORD) { throw new Error("SMTP_HOST, SMTP_PORT, SMTP_USER and SMTP_PASSWORD must be set to send email."); } cached = nodemailer.createTransport({ host: SMTP_HOST, port: Number(SMTP_PORT), secure: Number(SMTP_PORT) === 465, auth: { user: SMTP_USER, pass: SMTP_PASSWORD }, }); return cached; } export function getMailFrom(): string { return process.env.SMTP_FROM || "ANOUMA "; }