Skip to content

Commit fe5baaa

Browse files
BackendExpertJehanKandyAnupa1998
committed
Update LeaveController.js
Co-Authored-By: JehanKandy <[email protected]> Co-Authored-By: Anupa Gamage <[email protected]>
1 parent 0200d23 commit fe5baaa

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

server/Controllers/LeaveController.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const User = require('../Models/User')
22
const Leave = require('../Models/Leave')
33
const nodemailer = require('nodemailer');
4+
const Email = require('../Models/Email')
45

56
const transporter = nodemailer.createTransport({
67
service: 'gmail',
@@ -60,7 +61,14 @@ const LeaveController = {
6061
subject: "Notifications from ERP",
6162
text: "There is a new Leave to Approve from" + reqEmail,
6263
};
63-
// return res.json({ Status: "Success"})
64+
try {
65+
await transporter.sendMail(mailOptions);
66+
const email = new Email({ to, subject, body });
67+
await email.save();
68+
return res.json({ Status: "Success"})
69+
} catch (error) {
70+
return res.json({ Error: "Error While Sending Emails"})
71+
}
6472

6573
}
6674
else{

0 commit comments

Comments
 (0)