fix: added sender retry and handled fail
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user