jobapi.js
4.38 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import nodemailer from "nodemailer";
export default function (req, res) {
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASS,
},
});
const maillist =
Array.isArray(req.body?.maillist) && req.body?.maillist.length
? req.body.maillist
: ["gaurav.logicloop@gmail.com"];
const parsedData = req.body || {};
const buildRow = (label, value) => {
return `<tr>
<td style="width:30%;"><b>${label}:</b></td>
<td style="width:70%;">${value}</td>
</tr>`;
};
// Build table rows dynamically if data exists
let personalDetailsRows = "";
if (parsedData.name) personalDetailsRows += buildRow("Name", parsedData.name);
if (parsedData.email) personalDetailsRows += buildRow("Email", parsedData.email);
if (parsedData.mobile) personalDetailsRows += buildRow("Mobile", parsedData.mobile);
if (parsedData.jobTitle) personalDetailsRows += buildRow("Designation", parsedData.jobTitle);
if (parsedData.experience) personalDetailsRows += buildRow("Experience", parsedData.experience);
if (parsedData.Location) personalDetailsRows += buildRow("Job Location", parsedData.Location);
if (parsedData.organization) personalDetailsRows += buildRow("Current Company", parsedData.organization);
if (parsedData.jobType) personalDetailsRows += buildRow("Job Type", parsedData.jobType);
if (req.body?.resumeBase64?.name) {
personalDetailsRows += buildRow(
"Resume",
"✅ Resume Attached (" + req.body.resumeBase64.name + ")"
);
}
// build attachments if a resume was sent from the client
const attachments = [];
if (req.body?.resumeBase64) {
const file = req.body.resumeBase64;
attachments.push({
filename: file.name || "resume.pdf",
content: file.content,
encoding: "base64",
contentType: file.type || "application/pdf",
});
}
const mailData = {
from: "gaurav.logicloop@gmail.com",
to: maillist,
subject: `Alphion ${req.body?.FormSource || ""} 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%; border-collapse:separate;">
<tbody>
<tr>
<td align="center">
<table border="0" cellpadding="16" cellspacing="0" width="590" style="background-color:white; border-collapse:separate;">
<tbody>
<tr>
<td align="center">
<strong style="font-size:16px;">Welcome to Alphion</strong>
</td>
</tr>
<tr>
<td colspan="2">
<hr style="border-top:1px solid rgba(0,0,0,0.1); margin:16px 0;">
</td>
</tr>
<tr>
<td style="font-size:13px;">
<div style="margin-bottom:10px;">
Details below are enquiry from website!
</div>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr><td colspan="2"><b>Personal Details:</b></td></tr>
${personalDetailsRows}
</table>
</td>
</tr>
<tr>
<td colspan="2">
<hr style="border-top:1px solid rgba(0,0,0,0.1); margin:16px 0;">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td align="center">
<table border="0" cellpadding="8" cellspacing="0" width="590" style="background-color:#f1f1f1; color:#454748;">
<tbody>
<tr>
<td style="text-align:center; font-size:13px;"><br></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
`,
attachments,
};
transporter.sendMail(mailData, function (err, info) {
if (err) {
console.log("Error:", err);
return res.status(500).send("Error sending email");
}
console.log("Email sent:", info.response);
return res.send("success");
});
}