manage error log for email sender

This commit is contained in:
philc 2024-12-17 16:29:22 +01:00
parent 2ac8704f55
commit 04efb9f00c

View File

@ -346,6 +346,7 @@ Notifications.sendmail = async (data, tribe) => {
confsmtp = conftrib.smtp; confsmtp = conftrib.smtp;
if (!data.from || data.from == conf.emailcontact) data.from = conftrib.emailcontact; if (!data.from || data.from == conf.emailcontact) data.from = conftrib.emailcontact;
} }
// console.log(confsmtp)
const transporter = await nodemailer.createTransport(confsmtp); const transporter = await nodemailer.createTransport(confsmtp);
if (data.filelist) { if (data.filelist) {
data.attachments = []; data.attachments = [];
@ -365,10 +366,16 @@ Notifications.sendmail = async (data, tribe) => {
}; };
} }
//console.log("data:", data); //console.log("data:", data);
const res = await transporter.sendMail(data); let res;
//console.log(res) let error;
try{
res = await transporter.sendMail(data);
}catch(err){
console.log(err)
error=err
}
if ( if (
res.accepted && res && res.accepted &&
data.to.split(",").reduce((acc, m) => acc && res.accepted.includes(m), true) data.to.split(",").reduce((acc, m) => acc && res.accepted.includes(m), true)
) { ) {
data.accepted = res.accepted; data.accepted = res.accepted;
@ -379,12 +386,12 @@ Notifications.sendmail = async (data, tribe) => {
msg: "successfullsentemail", msg: "successfullsentemail",
data, data,
}; };
} else if (res.accepted && res.rejected) { } else if ( res && res.accepted && res.rejected) {
data.accepted = res.accepted; data.accepted = res.accepted;
data.rejected = res.rejected; data.rejected = res.rejected;
return { status: 410, ref: "Notifications", msg: "errsendmail", data }; return { status: 410, ref: "Notifications", msg: "errsendmail", data };
} else { } else {
data.errmailer = res.err; data.errmailer = error;
return { status: 417, ref: "Notifications", msg: "errsendmail", data }; return { status: 417, ref: "Notifications", msg: "errsendmail", data };
} }
}; };