fix: added sender retry and handled fail

This commit is contained in:
Riccardo
2023-12-16 08:56:20 +01:00
parent ac6b227870
commit bcc64eaef6
8 changed files with 199 additions and 138 deletions

View File

@@ -5,10 +5,7 @@ type EmailTemplate = {
template: JSX.Element;
};
export async function sendEmail(
to: string[],
{ subject, template }: EmailTemplate
) {
async function sendEmail(to: string[], { subject, template }: EmailTemplate) {
const resend = new Resend(process.env.RESEND_KEY);
try {
@@ -17,14 +14,42 @@ export async function sendEmail(
to,
subject,
react: template,
headers: {
'List-Unsubscribe': `<${process.env.HOME_URL}/unsubscribe>`
}
});
if (error) {
console.log(error);
return false;
}
} catch (error) {
console.log(error);
return false;
}
console.log('Email sent', subject, to.length);
return true;
}
export async function sender(
to: string[],
{ subject, template }: EmailTemplate
) {
let success = false;
let i = 5;
while (i < 5) {
const sent = await sendEmail(to, { subject, template });
if (sent) {
success = true;
break;
}
i++;
}
return success;
}