fix: update email sending logic to handle disabled state and improve error handling

This commit is contained in:
Marco Pedone 2025-08-22 16:58:05 +02:00
parent 283eb85066
commit 779df357bc
2 changed files with 19 additions and 22 deletions

View file

@ -57,7 +57,7 @@ const AnnuncioEdit: NextPageWithLayout<AnnuncioEditProps> = ({
if (!data) { if (!data) {
return <Status500 />; return <Status500 />;
} }
//todo avere scheda di condivizione scaricabile
return ( return (
<> <>
<AnnuncioEditForm data={data} /> <AnnuncioEditForm data={data} />

View file

@ -203,15 +203,7 @@ export const NewMail = async ({
db: db, db: db,
id: "EMAIL_OFF", id: "EMAIL_OFF",
}); });
if (emailFlag === "true") { if (emailFlag == "false") {
console.warn(
`Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
);
return {
success: true,
message: `Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
};
}
try { try {
const { html } = await genMail({ ...mail }); const { html } = await genMail({ ...mail });
await mailer({ await mailer({
@ -219,15 +211,20 @@ export const NewMail = async ({
subject: subject, subject: subject,
html, html,
}); });
if (userId) {
// Store the email in the database if userId is provided
await StoreEmail({ userId, data: mail });
}
} catch (e) { } catch (e) {
throw new TRPCError({ throw new TRPCError({
code: "INTERNAL_SERVER_ERROR", code: "INTERNAL_SERVER_ERROR",
message: "Errore nell'invio dell'email: " + (e as Error).message, message: "Errore nell'invio dell'email: " + (e as Error).message,
}); });
} }
} else {
console.warn(
`Email sending is disabled to:${to} subj:${subject} msgType: ${mail.mailType}`,
);
}
if (userId) {
// Store the email in the database if userId is provided
await StoreEmail({ userId, data: mail });
}
}; };