Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add custom email address for verification emails
Marc Seitz2d79f00e8177
diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.tsindex d90e1ccf..8d3d50b3 100644--- a/app/api/views-dataroom/route.ts+++ b/app/api/views-dataroom/route.ts@@ -362,7 +362,7 @@ export async function POST(request: NextRequest) {},});- waitUntil(sendOtpVerificationEmail(email, otpCode, true));+ waitUntil(sendOtpVerificationEmail(email, otpCode, true, link.teamId!));return NextResponse.json({type: "email-verification",diff --git a/app/api/views/route.ts b/app/api/views/route.tsindex 142bed75..ce39d08b 100644--- a/app/api/views/route.ts+++ b/app/api/views/route.ts@@ -249,7 +249,7 @@ export async function POST(request: NextRequest) {},});- waitUntil(sendOtpVerificationEmail(email, otpCode));+ waitUntil(sendOtpVerificationEmail(email, otpCode, false, link.teamId!));return NextResponse.json({type: "email-verification",message: "Verification email sent.",diff --git a/components/emails/otp-verification.tsx b/components/emails/otp-verification.tsxindex 618248b3..d64210d0 100644--- a/components/emails/otp-verification.tsx+++ b/components/emails/otp-verification.tsx@@ -7,6 +7,7 @@ import {Heading,Hr,Html,+ Img,Preview,Section,Tailwind,@@ -17,10 +18,12 @@ export default function OtpEmailVerification({email = "[email protected]",code = "123456",isDataroom = false,+ logo,}: {email: string;code: string;isDataroom: boolean;+ logo?: string;}) {return (<Html>@@ -29,9 +32,21 @@ export default function OtpEmailVerification({<Tailwind><Body className="mx-auto my-auto bg-white font-sans"><Container className="mx-auto my-10 w-[465px] p-5">- <Text className="mx-0 mb-8 mt-4 p-0 text-center text-2xl font-normal">- <span className="font-bold tracking-tighter">Papermark</span>- </Text>+ <div className="mx-0 mb-8 mt-4 p-0 text-center">+ {logo ? (+ <Img+ src={logo}+ alt="Logo"+ width="120"+ height="36"+ className="mx-auto"+ />+ ) : (+ <Text className="text-2xl font-normal">+ <span className="font-bold tracking-tighter">Papermark</span>+ </Text>+ )}+ </div><Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">Please confirm your email address</Heading>diff --git a/lib/edge-config/custom-email.ts b/lib/edge-config/custom-email.tsnew file mode 100644index 00000000..f8abfc1b--- /dev/null+++ b/lib/edge-config/custom-email.ts@@ -0,0 +1,23 @@+import { get } from "@vercel/edge-config";++export const getCustomEmail = async (teamId?: string) => {+ if (!process.env.EDGE_CONFIG || !teamId) {+ return null;+ }++ let customEmails: Record<string, string | null> = {};+ try {+ const result = await get("customEmail");+ // Make sure we get a valid object+ customEmails =+ typeof result === "object" && result !== null+ ? (result as Record<string, string | null>)+ : {};+ } catch (e) {+ // Error getting custom emails, return null+ return null;+ }++ // Return the custom email for the team if it exists+ return customEmails[teamId] || null;+};diff --git a/lib/emails/send-email-otp-verification.ts b/lib/emails/send-email-otp-verification.tsindex a8179fd4..5a10379f 100644--- a/lib/emails/send-email-otp-verification.ts+++ b/lib/emails/send-email-otp-verification.ts@@ -1,19 +1,40 @@-import OtpEmailVerification from "@/components/emails/otp-verification";-+import { getCustomEmail } from "@/lib/edge-config/custom-email";+import prisma from "@/lib/prisma";import { sendEmail } from "@/lib/resend";+import OtpEmailVerification from "@/components/emails/otp-verification";+export const sendOtpVerificationEmail = async (email: string,code: string,isDataroom: boolean = false,+ teamId: string,) => {+ let brand: { logo: string | null } | null = null;+ let from: string | undefined;++ const customEmail = await getCustomEmail(teamId);++ if (customEmail && teamId) {+ from = customEmail;++ // Get brand logo if we have a custom email+ brand = await prisma.brand.findUnique({+ where: { id: teamId },+ select: { logo: true },+ });+ }+const emailTemplate = OtpEmailVerification({email,code,isDataroom,+ logo: brand?.logo ?? undefined,});+try {await sendEmail({+ from,to: email,subject: `One-time passcode to access the ${isDataroom ? "dataroom" : "document"}`,react: emailTemplate,