import nodemailer from 'nodemailer'; import { config } from '../config'; let transporter: nodemailer.Transporter | null = null; function getTransporter(): nodemailer.Transporter { if (!transporter) { if (!config.smtp.host || !config.smtp.user) { console.warn('SMTP not configured. Email sending disabled.'); return null as any; } transporter = nodemailer.createTransport({ host: config.smtp.host, port: config.smtp.port, secure: config.smtp.secure, auth: { user: config.smtp.user, pass: config.smtp.pass, }, }); } return transporter; } export async function sendVerificationEmail(to: string, token: string): Promise { const transport = getTransporter(); if (!transport) { console.log(`[DEV] Verification email to ${to}: ${token}`); return; } const verificationUrl = `${config.corsOrigin}/verify-email?token=${token}`; await transport.sendMail({ from: config.smtp.from, to, subject: 'Verify your RealBlocks account', html: `

Welcome to RealBlocks!

Click the link below to verify your email address:

Verify Email

This link expires in 24 hours.

`, }); } export async function sendPasswordResetEmail(to: string, token: string): Promise { const transport = getTransporter(); if (!transport) { console.log(`[DEV] Password reset email to ${to}: ${token}`); return; } const resetUrl = `${config.corsOrigin}/reset-password?token=${token}`; await transport.sendMail({ from: config.smtp.from, to, subject: 'Reset your RealBlocks password', html: `

Password Reset Request

Click the link below to reset your password:

Reset Password

This link expires in 1 hour. If you didn't request this, ignore this email.

`, }); }