-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemailService.js
More file actions
38 lines (33 loc) · 1.14 KB
/
emailService.js
File metadata and controls
38 lines (33 loc) · 1.14 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
const nodemailer = require("nodemailer");
const dotenv = require("dotenv");
dotenv.config();
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_PASSWORD,
}
});
const sendLowStockAlert = (itemName, quantity) => {
const mailOptions = {
from: process.env.EMAIL_USER,
to: process.env.EMAIL_TO,
subject: `⚠ Low Stock Alert: ${itemName}`,
html: `
<h2 style="color: red;">🚨 Low Stock Alert! 🚨</h2>
<p><strong>Item:</strong> ${itemName}</p>
<p><strong>Remaining Stock:</strong> ${quantity} units</p>
<p style="color: red;">Please restock soon to avoid shortages.</p>
<hr>
<p>Best,<br>Biomedical Inventory System</p>
`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error("Error sending email:", error);
} else {
console.log("Low stock alert email sent:", info.response);
}
});
};
module.exports = sendLowStockAlert;