api changes
This commit is contained in:
@@ -1,32 +1,105 @@
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import nodemailer from "nodemailer";
|
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) {
|
export async function POST(req: Request) {
|
||||||
const body = await req.json();
|
const body = await req.json();
|
||||||
|
|
||||||
const transporter = nodemailer.createTransport({
|
// 🔥 Send response immediately
|
||||||
service: "gmail",
|
const response = NextResponse.json({ success: true });
|
||||||
auth: {
|
|
||||||
user: process.env.EMAIL_USER,
|
|
||||||
pass: process.env.EMAIL_PASS,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await transporter.sendMail({
|
// 🔥 Send email in background
|
||||||
from: process.env.EMAIL_USER,
|
transporter
|
||||||
|
.sendMail({
|
||||||
|
from: process.env.SMTP_USER,
|
||||||
to: "lead@winixco.com",
|
to: "lead@winixco.com",
|
||||||
subject: "New Demo Request",
|
subject: "New Demo Request",
|
||||||
html: `
|
html: `
|
||||||
<h2>New Demo Lead</h2>
|
<!DOCTYPE html>
|
||||||
<p><strong>Name:</strong> ${body.name}</p>
|
<html>
|
||||||
<p><strong>Email:</strong> ${body.email}</p>
|
<body style="margin:0;padding:0;background-color:#f4f6f8;font-family:Arial,sans-serif;">
|
||||||
<p><strong><Phone Number:</strong>${body.phoneNumber}</p>
|
|
||||||
<p><strong>Company:</strong> ${body.company}</p>
|
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f4f6f8;padding:20px 0;">
|
||||||
<p><strong>Designation:</strong> ${body.designation}</p>
|
<tr>
|
||||||
<p><strong>Solution:</strong> ${body.solution}</p>
|
<td align="center">
|
||||||
<p><strong>Description:</strong> ${body.description}</p>
|
|
||||||
|
<!-- 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 NextResponse.json({ success: true });
|
return response;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user