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: `

Hey ${name} 👋

Please verify your email address by clicking the button below:

Verify Email

Or copy this link in your browser:
${verifyUrl}

This link is valid for 24 hours.


If you didn't register, please ignore this email.

`, text: `Hey ${name},\n\nPlease verify your email: ${verifyUrl}\n\nThis link is valid for 24 hours.\n\n– ${appName}`, }); } /** * Send a federation meeting invitation email. * @param {string} to – recipient email * @param {string} name – recipient display name * @param {string} fromUser – sender federated address (user@domain) * @param {string} roomName – name of the invited room * @param {string} message – optional personal message * @param {string} inboxUrl – URL to the federation inbox * @param {string} appName – branding app name (default "Redlight") */ export async function sendFederationInviteEmail(to, name, fromUser, roomName, message, inboxUrl, appName = 'Redlight') { if (!transporter) return; // silently skip if SMTP not configured const from = process.env.SMTP_FROM || process.env.SMTP_USER; await transporter.sendMail({ from: `"${appName}" <${from}>`, to, subject: `${appName} – Meeting invitation from ${fromUser}`, html: `

Hey ${name} 👋

You have received a meeting invitation from ${fromUser}.

Room:

${roomName}

${message ? `

"${message}"

` : ''}

View Invitation


Open the link above to accept or decline the invitation.

`, text: `Hey ${name},\n\nYou have received a meeting invitation from ${fromUser}.\nRoom: ${roomName}${message ? `\nMessage: "${message}"` : ''}\n\nView invitation: ${inboxUrl}\n\n– ${appName}`, }); }