Skip to content

Commit

Permalink
added after verification email
Browse files Browse the repository at this point in the history
  • Loading branch information
kvineet002 committed Aug 25, 2024
1 parent 4a859d1 commit 729524f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Backend/controllers/requestsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request } from "../Models/Request.js";
import emailService from "../services/emailService.js";

async function createRequest(req, res) {
try {
Expand Down Expand Up @@ -73,8 +74,12 @@ async function ApproveRequest(req,res){
return res.status(404).json({ message: 'Request not found' });
}
request.Status="Approved";
// const senderEmail=request["Sender email"]
// console.log(senderEmail)
await request.save();
return res.status(200).json({ message: 'Request Withdrawn successfully'});
await emailService.sendVerificationSuccess(request);
// console.log(request)
return res.status(200).json({ message: 'Request Approved successfully'});
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
Expand Down
60 changes: 59 additions & 1 deletion Backend/services/emailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,65 @@ const emailService = {


await transporter.sendMail(mailOptions);
}
},
sendVerificationSuccess: async function sendVerificationSuccess(requestDetails) {
const email=requestDetails["Sender email"]
const senderName=requestDetails["Sender Name"]
const requestBody=requestDetails.subject
let transporter = nodemailer.createTransport({
host: 'smtp.office365.com',
port: 587,
secure: false,
auth: {
user: EMAIL,
pass: PASSWORD,
},
});

let mailOptions = {
from: EMAIL,
to: `${email}`,
subject: 'Congratulations! Your Request Has Been Verified',
html: `
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #212121;
color: #ffffff;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
border: 1px solid #555;
background-color: #000;
text-align: center;
}
h2 {
color: #fff;
}
p {
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<h2>Congratulations, ${senderName}!</h2>
<p>Your request has been successfully verified. Below is the summary of your request:</p>
<div class="request-body">
<p>${requestBody}</p>
</div>
<p>Thank you for using our portal!</p>
</div>
</body>
</html>
`,
};
await transporter.sendMail(mailOptions);
},
};


Expand Down

0 comments on commit 729524f

Please sign in to comment.