-
Notifications
You must be signed in to change notification settings - Fork 2
/
email.js
98 lines (89 loc) · 2.49 KB
/
email.js
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
import nodemailer from "nodemailer";
export const sendEmail = async (jobs, jobHrFeedbackResults) => {
const jobHrFeedbackResultsMapped = jobHrFeedbackResults.map(
(jobHrFeedbackResult) => {
return {
id: jobHrFeedbackResult.id,
feedback: jobHrFeedbackResult.jobHrFeedback,
};
}
);
// Create a nodemailer transporter
const transporter = nodemailer.createTransport({
host: "smtp.office365.com",
port: 587,
secure: false,
auth: {
user: "[email protected]", // Replace with your Outlook email address
pass: "abc123", // Replace with your Outlook password
},
});
try {
// Compose the email message
const message = {
from: "[email protected]", // Sender email address
to: "[email protected]", // Recipient email address
subject: "New Job Opportunities",
html: `<html>
<head>
<style>
.job-card {
border: 1px solid #ccc;
padding: 10px;
margin-bottom: 20px;
}
.job-title {
color: #333;
margin-bottom: 10px;
}
.job-details {
margin-bottom: 10px;
}
.job-link {
color: blue;
text-decoration: underline;
}
.job-keywords {
margin-top: 10px;
}
</style>
</head>
<body>
${jobs
.map(
(job) => `
<div class="job-card">
<h2 class="job-title">${job.title}</h2>
<p><strong>Company:</strong> ${job.company}</p>
<p><strong>Location:</strong> ${job.location}</p>
<p class="job-details"><strong>Job Description:</strong></p>
<p>${job.details}</p>
<p class="job-details"><strong>You HR Helper Feedback:</strong></p>
<p>"${
(
jobHrFeedbackResultsMapped.find(
(f) => f.id.toString() === job.id.toString()
) || {}
).feedback || ""
}"</p>
<p><strong>Link:</strong> <a class="job-link" href="${job.url}">${
job.url
}</a></p>
<p class="job-keywords"><strong>Keywords:</strong> ${job.keywords.join(
", "
)}</p>
</div>
`
)
.join("")}
</body>
</html>`,
};
// Send the email
const info = await transporter.sendMail(message);
console.log("Email sent:", info.messageId);
} catch (error) {
console.log("Error sending email:", error);
}
};
export default sendEmail;