api changes

This commit is contained in:
2026-03-19 21:02:51 +05:30
parent cc6d689e9f
commit 174faf5ccd

View File

@@ -1,32 +1,105 @@
import { NextResponse } from "next/server";
import nodemailer from "nodemailer";
const row = (label: string, value: string) => `
<tr>
<td style="padding:10px 0;border-bottom:1px solid #e2e8f0;">
<strong style="display:block;color:#0f172a;margin-bottom:4px;">
${label}
</strong>
<span style="color:#475569;">
${value}
</span>
</td>
</tr>
`;
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
pool: true, // 🔥 enables connection pooling
maxConnections: 5,
maxMessages: 100,
});
export async function POST(req: Request) {
const body = await req.json();
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
// 🔥 Send response immediately
const response = NextResponse.json({ success: true });
await transporter.sendMail({
from: process.env.EMAIL_USER,
to: "lead@winixco.com",
subject: "New Demo Request",
html: `
<h2>New Demo Lead</h2>
<p><strong>Name:</strong> ${body.name}</p>
<p><strong>Email:</strong> ${body.email}</p>
<p><strong><Phone Number:</strong>${body.phoneNumber}</p>
<p><strong>Company:</strong> ${body.company}</p>
<p><strong>Designation:</strong> ${body.designation}</p>
<p><strong>Solution:</strong> ${body.solution}</p>
<p><strong>Description:</strong> ${body.description}</p>
`,
});
// 🔥 Send email in background
transporter
.sendMail({
from: process.env.SMTP_USER,
to: "lead@winixco.com",
subject: "New Demo Request",
html: `
<!DOCTYPE html>
<html>
<body style="margin:0;padding:0;background-color:#f4f6f8;font-family:Arial,sans-serif;">
return NextResponse.json({ success: true });
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f6f8;padding:20px 0;">
<tr>
<td align="center">
<!-- Main Container -->
<table width="600" cellpadding="0" cellspacing="0" style="background:#ffffff;border-radius:12px;overflow:hidden;box-shadow:0 10px 30px rgba(0,0,0,0.08);">
<!-- Header -->
<tr>
<td style="background:linear-gradient(90deg,#2563eb,#4f46e5);padding:24px;text-align:center;color:#ffffff;">
<h1 style="margin:0;font-size:22px;">New Demo Request</h1>
<p style="margin:6px 0 0;font-size:14px;opacity:0.9;">
Winixco Lead Notification
</p>
</td>
</tr>
<!-- Body -->
<tr>
<td style="padding:24px;">
<table width="100%" cellpadding="0" cellspacing="0" style="font-size:14px;color:#334155;">
${row("Name", body.name)}
${row("Email", body.email)}
${row("Phone Number", body.phoneNumber)}
${row("Company", body.company)}
${row("Designation", body.designation)}
${row("Solution", body.solution)}
${row("Description", body.description || "-")}
</table>
</td>
</tr>
<!-- Footer -->
<tr>
<td style="background:#f1f5f9;padding:16px;text-align:center;font-size:12px;color:#64748b;">
This email was generated from your website demo request form.
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
`,
})
.catch((err) => {
console.error("Email failed:", err);
});
return response;
}