import nodemailer from 'nodemailer'; // Email configuration const smtpHost = process.env.SMTP_HOST || ''; const smtpPort = process.env.SMTP_PORT ? parseInt(process.env.SMTP_PORT, 10) : 587; const smtpUser = process.env.SMTP_USER || ''; const smtpPass = process.env.SMTP_PASS || ''; const fromEmail = process.env.FROM_EMAIL || 'noreply@nexaflow.com'; const adminEmail = process.env.ADMIN_EMAIL || 'admin@nexaflow.com'; const isConfigured = Boolean(smtpHost && smtpUser && smtpPass); // Create reusable transporter object using the default SMTP transport const transporter = nodemailer.createTransport({ host: smtpHost, port: smtpPort, secure: smtpPort === 465, // true for 465, false for other ports auth: { user: smtpUser, // generated ethereal user pass: smtpPass, // generated ethereal password }, }); interface InquiryData { referenceNumber: string; name: string; email: string; projectType: string; budget?: string; timeline?: string; description: string; company?: string; phone?: string; } export const sendQuoteConfirmation = async (inquiry: InquiryData) => { const targetEmail = inquiry.email; const subject = `Quote Request Received - Ref: ${inquiry.referenceNumber}`; const htmlBody = `

Hello ${inquiry.name},

Thank you for requesting a quote from NexaFlow! We have received your inquiry.

Your Reference Number: ${inquiry.referenceNumber}


Project Details Summarized:

Our team will review your requirements and get back to you within 24 hours with a detailed proposal or further questions.

Best regards,
The NexaFlow Team

`; return sendEmail(targetEmail, subject, htmlBody); }; export const sendAdminNotification = async (inquiry: InquiryData) => { const subject = `New Quote Request - ${inquiry.projectType.toUpperCase()} - Ref: ${inquiry.referenceNumber}`; const htmlBody = `

New Quote Request Received

A new inquiry has been submitted via the website form.


Reference Number: ${inquiry.referenceNumber}

Client Details:

Project Details:

Description:

${inquiry.description}

`; return sendEmail(adminEmail, subject, htmlBody); }; const sendEmail = async (to: string, subject: string, html: string) => { if (!isConfigured) { // Fallback for local development or when SMTP is not configured console.log('-------------------------------------------------------'); console.log('📧 EMAIL MOCK (SMTP not configured)'); console.log(`To: ${to}`); console.log(`From: ${fromEmail}`); console.log(`Subject: ${subject}`); console.log('Body HTML preview:'); console.log(html); console.log('-------------------------------------------------------'); return true; } try { const info = await transporter.sendMail({ from: `"NexaFlow" <${fromEmail}>`, // sender address to, // list of receivers subject, // Subject line html, // html body }); console.log("Message sent: %s", info.messageId); return true; } catch (error) { console.error("Error sending email:", error); return false; } };