import nodemailer from "nodemailer"; const smtpHost = process.env.SMTP_HOST; const smtpPort = parseInt(process.env.SMTP_PORT || "465", 10); const smtpUser = process.env.SMTP_USER; const smtpPassword = process.env.SMTP_PASSWORD; const fromEmail = process.env.SMTP_FROM_EMAIL || "no-reply@aethex.dev"; const verifySupportEmail = process.env.VERIFY_SUPPORT_EMAIL ?? "support@aethex.biz"; let transporter: nodemailer.Transporter | null = null; function getTransporter() { if (transporter) return transporter; if (!smtpHost || !smtpUser || !smtpPassword) { throw new Error( "SMTP configuration is missing. Set SMTP_HOST, SMTP_USER, and SMTP_PASSWORD.", ); } transporter = nodemailer.createTransport({ host: smtpHost, port: smtpPort, secure: smtpPort === 465, auth: { user: smtpUser, pass: smtpPassword, }, }); return transporter; } export const emailService = { get isConfigured() { return Boolean(smtpHost && smtpUser && smtpPassword); }, async sendVerificationEmail(params: { to: string; verificationUrl: string; fullName?: string | null; }) { const transporter = getTransporter(); const { to, verificationUrl, fullName } = params; const safeName = fullName?.trim() || "there"; const subject = "Verify your AeThex account"; const previewText = "Confirm your AeThex account to access the dashboard."; const html = `
Click the button below to verify your account and unlock your personal dashboard.
If the button does not work, paste this link into your browser:
${verificationUrl}
Didn't create an account? Please ignore this email or contact ${verifySupportEmail}.
${safeInviter} sent you an invitation to connect and collaborate on AeThex.
${message ? `${message}` : ""}
If the button does not work, paste this link into your browser:
${inviteUrl}