Files
dataroom/lib/emails/send-dataroom-digest-notification.ts

46 lines
1.0 KiB
TypeScript

import DataroomDigestNotification from "@/components/emails/dataroom-digest-notification";
import { sendEmail } from "@/lib/resend";
export const sendDataroomDigestNotification = async ({
dataroomName,
documents,
senderEmail,
to,
url,
preferencesUrl,
frequency,
}: {
dataroomName: string;
documents: { documentName: string }[];
senderEmail: string;
to: string;
url: string;
preferencesUrl: string;
frequency: "daily" | "weekly";
}) => {
const count = documents.length;
const periodLabel = frequency === "daily" ? "today" : "this week";
try {
await sendEmail({
to,
subject: `${count} new document${count !== 1 ? "s" : ""} in ${dataroomName} ${periodLabel}`,
react: DataroomDigestNotification({
senderEmail,
dataroomName,
documents,
url,
preferencesUrl,
frequency,
}),
test: process.env.NODE_ENV === "development",
system: true,
unsubscribeUrl: preferencesUrl,
});
} catch (e) {
console.error(e);
throw e;
}
};