import nodemailer from "nodemailer"; // Configure transport based on environment const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST || "localhost", port: parseInt(process.env.SMTP_PORT || "1025"), secure: process.env.SMTP_SECURE === "true", auth: process.env.SMTP_USER && process.env.SMTP_PASS ? { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS, } : undefined, // MailHog doesn't need auth in dev }); export async function sendVerificationEmail( to: string, name: string, token: string, ): Promise { const baseUrl = process.env.APP_URL || `http://localhost:${process.env.PORT || 3000}`; const verifyUrl = `${baseUrl}/verify?token=${token}`; const mailOptions: Record = { from: process.env.SMTP_FROM || `"GammaDesk" `, to, subject: "Verify your GammaDesk account", text: `GammaDesk - Verify Your Account\n\nHello ${name},\n\nThanks for signing up! Please verify your email by visiting:\n\n${verifyUrl}\n\nThis link expires in 24 hours. If you didn't create this account, you can safely ignore this email.`, html: `

Welcome to GammaDesk, ${name}!

Thanks for signing up. Please verify your email address by clicking the button below.

Verify Email Address

This link will expire in 24 hours.
If you didn't create this account, you can safely ignore this email.

`, }; try { await transporter.sendMail(mailOptions); console.log(`[Email] Verification email sent to ${to}`); return true; } catch (error) { console.error("[Email] Failed to send verification email:", error); return false; } }