import nodemailer from 'nodemailer'; let transporter; export function initMailer() { const host = process.env.SMTP_HOST; const port = parseInt(process.env.SMTP_PORT || '587', 10); const user = process.env.SMTP_USER; const pass = process.env.SMTP_PASS; if (!host || !user || !pass) { console.warn('⚠️ SMTP not configured – email verification disabled'); return false; } transporter = nodemailer.createTransport({ host, port, secure: port === 465, auth: { user, pass }, }); console.log('✅ SMTP mailer configured'); return true; } export function isMailerConfigured() { return !!transporter; } /** * Send the verification email with a clickable link. * @param {string} to – recipient email * @param {string} name – user's display name * @param {string} verifyUrl – full verification URL * @param {string} appName – branding app name (default "Redlight") */ export async function sendVerificationEmail(to, name, verifyUrl, appName = 'Redlight') { if (!transporter) { throw new Error('SMTP not configured'); } const from = process.env.SMTP_FROM || process.env.SMTP_USER; await transporter.sendMail({ from: `"${appName}" <${from}>`, to, subject: `${appName} – Verify your email`, html: `
Please verify your email address by clicking the button below:
Or copy this link in your browser:
${verifyUrl}
This link is valid for 24 hours.
If you didn't register, please ignore this email.