import nodemailer from 'nodemailer'; import config from '../config.js'; let transporter = null; if (config.email.host) { transporter = nodemailer.createTransport({ host: config.email.host, port: config.email.port, secure: config.email.secure, auth: config.email.user ? { user: config.email.user, pass: config.email.pass } : undefined, }); } export async function sendVerificationEmail(to, link) { const subject = 'Verify your Fertig Classic Games account'; const text = `Welcome! Confirm your email by visiting:\n\n${link}\n\nThis link expires in ${config.email.verificationTtlHours} hour(s).`; const html = `
Welcome!
Confirm your email by clicking the link below:
This link expires in ${config.email.verificationTtlHours} hour(s).
`; if (!transporter) { console.log(`\n[mailer:dev] Verification link for ${to}:\n ${link}\n`); return { delivered: false, devLogged: true }; } try { await transporter.sendMail({ from: config.email.from, to, subject, text, html, }); return { delivered: true, devLogged: false }; } catch (err) { console.error(`[mailer] Failed to send verification email to ${to}:`, err); return { delivered: false, devLogged: false, error: err.message }; } }