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: `
Hello ${booking.userName},
Your table tennis court booking has been confirmed:
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.
Hello ${booking.userName},
Your table tennis court booking has been cancelled:
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.