import nodemailer from 'nodemailer'; import { config } from '../config/config'; export class EmailService { private transporter: nodemailer.Transporter; constructor() { this.transporter = nodemailer.createTransport({ host: config.email.host, port: config.email.port, secure: config.email.port === 465, auth: { user: config.email.user, pass: config.email.password, }, }); } async sendVerificationEmail(to: string, token: string) { const verificationLink = `${config.frontendUrl}/verify/${token}`; const content = `
Please click the button below to verify your email address:
Or copy and paste this link into your browser:
${verificationLink}
This link will expire in 24 hours.
`; const html = this.getHtmlTemplate('Verify your email address', content); await this.sendEmail(to, 'Verify your email', html); } async sendPasswordResetEmail(to: string, token: string) { const resetLink = `${config.frontendUrl}/reset-password/${token}`; const content = `You requested a password reset. Click the button below to reset your password:
Or copy and paste this link into your browser:
${resetLink}
If you didn't request this, please ignore this email.
`; const html = this.getHtmlTemplate('Reset your password', content); await this.sendEmail(to, 'Reset your password', html); } async sendContactMessageNotification(data: { name: string; email: string; subject?: string; message: string }) { const content = `You have received a new contact message from ${data.name} (${data.email}).
Subject: ${data.subject || 'No Subject'}
${data.message}
`; const html = this.getHtmlTemplate('New Contact Message', content); // Send to the configured notification emails const recipients = config.email.contactNotificationEmails; await this.sendEmail(recipients.join(','), `New Contact Message: ${data.subject || 'No Subject'}`, html); } private getHtmlTemplate(title: string, content: string): string { const logoUrl = 'https://res.cloudinary.com/dmxoohiwo/image/upload/v1764315105/logo_fpczsd.png'; const currentYear = new Date().getFullYear(); return `