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} – E-Mail bestätigen / Verify your email`, html: `
Bitte bestätige deine E-Mail-Adresse, indem du auf den folgenden Button klickst:
Oder kopiere diesen Link in deinen Browser:
${verifyUrl}
Der Link ist 24 Stunden gültig.
Falls du dich nicht registriert hast, ignoriere diese E-Mail.