forked from CSI-KJSCE/appointment_to_examiner
coursePanel dropdown, 6 emails per subject
This commit is contained in:
@@ -17,7 +17,7 @@ const storage = multer.diskStorage({
|
||||
const upload = multer({ storage });
|
||||
|
||||
// Route to handle email sending with file attachment
|
||||
router.post("/", upload.single("file"), async (req, res) => {
|
||||
router.post("/excel", upload.single("file"), async (req, res) => {
|
||||
const { teacher, fileName, recipientEmail } = req.body;
|
||||
|
||||
if (!teacher || !fileName || !recipientEmail || !req.file) {
|
||||
@@ -31,9 +31,12 @@ router.post("/", upload.single("file"), async (req, res) => {
|
||||
user: "swdc.ate@gmail.com", // Replace with your email
|
||||
pass: "umlc hbkr dpga iywd", // Replace with your app-specific password or token
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false, // Ignore self-signed certificate errors
|
||||
},
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 15000,
|
||||
socketTimeout: 15000,
|
||||
greetingTimeout: 15000,
|
||||
socketTimeout: 15000,
|
||||
});
|
||||
|
||||
// Email options
|
||||
@@ -52,17 +55,18 @@ If you have any queries, please contact the H.O.D or the Examination In-charge.
|
||||
|
||||
Your cooperation regarding the upcoming examination duties is highly solicited.`,
|
||||
attachments: [
|
||||
{
|
||||
filename: fileName,
|
||||
path: req.file.path, // Use the uploaded file's path
|
||||
},
|
||||
{
|
||||
filename: fileName,
|
||||
path: req.file.path, // Use the uploaded file's path
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
// Send email
|
||||
await transporter.sendMail(mailOptions);
|
||||
transporter.close();
|
||||
|
||||
// Delete the temporary file after sending the email
|
||||
fs.unlinkSync(req.file.path);
|
||||
@@ -74,4 +78,64 @@ Your cooperation regarding the upcoming examination duties is highly solicited.`
|
||||
}
|
||||
});
|
||||
|
||||
// Route to send emails with PDF attachments
|
||||
router.post("/pdf", upload.single("pdfFile"), async (req, res) => {
|
||||
const { fileName, recipientEmail, role, courseName } = req.body;
|
||||
|
||||
if (!fileName || !recipientEmail || !role || !courseName || !req.file) {
|
||||
return res.status(400).json({ error: "Missing required fields or file" });
|
||||
}
|
||||
|
||||
// Configure Nodemailer transporter
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: "gmail",
|
||||
auth: {
|
||||
user: "swdc.ate@gmail.com", // Replace with your email
|
||||
pass: "umlc hbkr dpga iywd", // Replace with your app-specific password
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
connectionTimeout: 15000,
|
||||
greetingTimeout: 15000,
|
||||
socketTimeout: 15000,
|
||||
});
|
||||
|
||||
// Email options
|
||||
const mailOptions = {
|
||||
from: "SWDC Admin <swdc.ate@gmail.com>",
|
||||
to: recipientEmail,
|
||||
subject: `Appointment as ${role} - ${courseName}`,
|
||||
text: `Dear teacher,
|
||||
|
||||
You have been appointed as a ${role} for the course "${courseName}".
|
||||
Please find your appointment letter attached.
|
||||
|
||||
If you have any queries, please contact the Examination In-charge.
|
||||
|
||||
Best regards,
|
||||
Examination Department`,
|
||||
attachments: [
|
||||
{
|
||||
filename: fileName,
|
||||
path: req.file.path, // Path to the uploaded PDF
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
try {
|
||||
// Send email
|
||||
await transporter.sendMail(mailOptions);
|
||||
transporter.close();
|
||||
|
||||
// Delete the PDF file after sending
|
||||
// fs.unlinkSync(req.file.path);
|
||||
|
||||
res.status(200).json({ message: "Email sent successfully" });
|
||||
} catch (error) {
|
||||
console.error("Error sending email:", error);
|
||||
res.status(500).json({ error: "Failed to send email" });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user