feat: updated Resend with batch emails

This commit is contained in:
Riccardo
2024-01-22 20:11:00 +01:00
parent 29067035e8
commit 551bff815f
4 changed files with 112 additions and 160 deletions

View File

@@ -12,16 +12,19 @@ export async function sender(
const resend = new Resend(process.env.RESEND_KEY);
try {
// TODO: adjust code once Resend supports batch sending
const { error } = await resend.emails.send({
from: process.env.RESEND_FROM!,
to,
subject,
react: template,
headers: {
'List-Unsubscribe': `<${process.env.HOME_URL}/unsubscribe>`
}
});
const { error } = await resend.batch.send(
to.map(t => {
return {
from: process.env.RESEND_FROM!,
to: t,
subject,
react: template,
headers: {
'List-Unsubscribe': `<${process.env.HOME_URL}/unsubscribe>`
}
};
})
);
if (error) {
console.log(error);