sendEmailHome.js
2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import nodemailer from "nodemailer";
export default async function handler(req, res) {
if (req.method !== "POST") {
return res.status(405).json({ error: "Method not allowed" });
}
const transporter = nodemailer.createTransport({
host: "smtp.office365.com",
port: 587,
secure: false, // use TLS, not SSL
auth: {
user: "support@advithitec.in",
pass: "supp@123",
},
tls: {
rejectUnauthorized: false,
},
});
const maillist = ["support@advithitec.in"];
const mailData = {
from: "support@advithitec.in",
to: maillist,
subject: "Advith Consulting Service Form Leads",
html: `
<table border="0" cellpadding="0" cellspacing="0" style="padding-top:35px; background-color:#f1f1f1; font-family:Verdana,Arial,sans-serif; color:#454748; width:100%;">
<tbody>
<tr>
<td align="center">
<table width="590" cellpadding="0" cellspacing="0" style="background-color:#fff; color:#454748; padding:16px;">
<tr>
<td align="center">
<strong style="font-size:16px;">Welcome to Advith Consulting</strong>
</td>
</tr>
<tr><td><hr style="border:1px solid #ddd; margin:16px 0;" /></td></tr>
<tr>
<td>
<p>Details below are enquiry from website:</p>
<table width="100%" cellpadding="4" cellspacing="0" style="font-size:13px;">
<tr><td colspan="2"><b>Personal Details:</b></td></tr>
<tr><td width="30%">Name:</td><td width="70%">${req.body.Name || ""}</td></tr>
<tr><td>Email:</td><td>${req.body.Email || ""}</td></tr>
<tr><td>Mobile:</td><td>${req.body.Mobile || ""}</td></tr>
<tr><td>Company/Service:</td><td>${req.body.service || ""}</td></tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
`,
};
try {
const info = await transporter.sendMail(mailData);
console.log("✅ Email sent:", info.response);
res.status(200).json({ success: true, message: "Email sent successfully" });
} catch (error) {
console.error("❌ Email send failed:", error);
res.status(500).json({ success: false, error: "Failed to send email", details: error.message });
}
}