import nodemailer from 'nodemailer'; interface EmailOptions { to: string; subject: string; html: string; } // Create reusable transporter object using SMTP transport const transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: process.env.EMAIL_USER, pass: process.env.EMAIL_PASSWORD, // Use App Password for Gmail }, }); export async function sendEmail({ to, subject, html }: EmailOptions) { try { const info = await transporter.sendMail({ from: `"Table Tennis Booking" <${process.env.EMAIL_USER}>`, to, subject, html, }); console.log('Email sent: %s', info.messageId); return { success: true, messageId: info.messageId }; } catch (error) { console.error('Error sending email:', error); return { success: false, error }; } } export function generateBookingConfirmationEmail(booking: { id: string; date: string; startTime: string; endTime: string; courtName: string; userName: string; }) { return { subject: 'Booking Confirmation - Table Tennis Court', html: `

Booking Confirmed!

Hello ${booking.userName},

Your table tennis court booking has been confirmed:

Booking Details

Booking ID: ${booking.id}

Date: ${booking.date}

Time: ${booking.startTime} - ${booking.endTime}

Court: ${booking.courtName}

Please arrive 5 minutes before your booking time. If you need to cancel or modify your booking, please log in to your account.

Thank you for choosing our table tennis facility!


This is an automated email. Please do not reply to this message.

`, }; } export function generateBookingCancellationEmail(booking: { id: string; date: string; startTime: string; endTime: string; courtName: string; userName: string; }) { return { subject: 'Booking Cancelled - Table Tennis Court', html: `

Booking Cancelled

Hello ${booking.userName},

Your table tennis court booking has been cancelled:

Cancelled Booking Details

Booking ID: ${booking.id}

Date: ${booking.date}

Time: ${booking.startTime} - ${booking.endTime}

Court: ${booking.courtName}

You can make a new booking anytime through our booking system.

Thank you for using our table tennis facility!


This is an automated email. Please do not reply to this message.

`, }; }