import nodemailer from 'nodemailer' let transporter: nodemailer.Transporter | null = null function getTransporter(): nodemailer.Transporter | null { if (transporter) return transporter const host = process.env.SMTP_HOST if (!host) return null transporter = nodemailer.createTransport({ host, port: Number(process.env.SMTP_PORT) || 587, secure: Number(process.env.SMTP_PORT) === 465, auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS } }) return transporter } export async function sendOrderConfirmation(email: string, orderId: string, totalSats: number): Promise { const t = getTransporter() if (!t) return await t.sendMail({ from: process.env.SMTP_FROM || 'orders@antonym.fashion', to: email, subject: `Order Confirmed - ${orderId}`, text: `Your order ${orderId} for ${totalSats.toLocaleString()} sats has been confirmed.\n\nTrack your order: ${process.env.SITE_URL || 'http://localhost:3333'}/order/${orderId}` }) } export async function sendStatusUpdate(email: string, orderId: string, status: string, note?: string): Promise { const t = getTransporter() if (!t) return const noteText = note ? `\n\nNote: ${note}` : '' await t.sendMail({ from: process.env.SMTP_FROM || 'orders@antonym.fashion', to: email, subject: `Order ${orderId} - ${status.charAt(0).toUpperCase() + status.slice(1)}`, text: `Your order ${orderId} status has been updated to: ${status}${noteText}\n\nTrack your order: ${process.env.SITE_URL || 'http://localhost:3333'}/order/${orderId}` }) }