Files
newsletter-hackernews/utils/sender.ts
2023-12-05 20:13:29 +01:00

31 lines
552 B
TypeScript

import { Resend } from 'resend';
type EmailTemplate = {
subject: string;
template: JSX.Element;
};
export async function sendEmail(
to: string[],
{ subject, template }: EmailTemplate
) {
const resend = new Resend(process.env.RESEND_KEY);
try {
const { error } = await resend.emails.send({
from: process.env.RESEND_FROM!,
to,
subject,
react: template,
});
if (error) {
console.log(error);
}
} catch (error) {
console.log(error);
}
console.log('Email sent', subject, to.length);
}