mirror of
https://github.com/Ravinou/borgwarehouse
synced 2024-05-04 14:53:15 +02:00
feat: send mail if user has enabled option
This commit is contained in:
parent
52f84bdfeb
commit
06d88380f3
|
@ -126,11 +126,9 @@ export default async function handler(req, res) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
console.log(repoListToSendAlert);
|
||||
//PART 4 : Send the mail alert
|
||||
if (repoListToSendAlert.length > 0) {
|
||||
// Read user informations
|
||||
console.log(repoListToSendAlert);
|
||||
try {
|
||||
//Read the email of the user
|
||||
usersList = await fs.readFile(
|
||||
|
@ -139,8 +137,6 @@ export default async function handler(req, res) {
|
|||
);
|
||||
//Parse the usersList
|
||||
usersList = JSON.parse(usersList);
|
||||
|
||||
console.log('test');
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
|
@ -148,27 +144,30 @@ export default async function handler(req, res) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//Send mail
|
||||
//Create the SMTP Transporter
|
||||
const transporter = nodemailerSMTP();
|
||||
//Mail options
|
||||
const mailData = emailTest(
|
||||
usersList[0].email,
|
||||
usersList[0].username
|
||||
);
|
||||
transporter.sendMail(mailData, function (err, info) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(400).json({
|
||||
message:
|
||||
'An error occured while sending the email : ' + err,
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
console.log(info);
|
||||
}
|
||||
});
|
||||
// If the user has enabled email alerts
|
||||
if (usersList[0].emailAlert) {
|
||||
//Send mail
|
||||
//Create the SMTP Transporter
|
||||
const transporter = nodemailerSMTP();
|
||||
//Mail options
|
||||
const mailData = emailTest(
|
||||
usersList[0].email,
|
||||
usersList[0].username
|
||||
);
|
||||
transporter.sendMail(mailData, function (err, info) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(400).json({
|
||||
message:
|
||||
'An error occured while sending the email : ' +
|
||||
err,
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
console.log(info);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//PART 5 : Sucess
|
||||
|
|
Loading…
Reference in a new issue