From 98a70aa65f982fd989dc94978fbd26ff59a06cb1 Mon Sep 17 00:00:00 2001 From: Steven Tey Date: Thu, 27 Nov 2025 19:00:40 -0800 Subject: [PATCH] Upgrade Resend --- packages/email/src/send-via-resend.ts | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/email/src/send-via-resend.ts b/packages/email/src/send-via-resend.ts index b042b3d11b7..fa4e8c796a4 100644 --- a/packages/email/src/send-via-resend.ts +++ b/packages/email/src/send-via-resend.ts @@ -1,8 +1,11 @@ +import type { CreateEmailOptions } from "resend"; import { resend } from "./resend"; import { VARIANT_TO_FROM_MAP } from "./resend/constants"; import { ResendBulkEmailOptions, ResendEmailOptions } from "./resend/types"; -const resendEmailForOptions = (opts: ResendEmailOptions) => { +const resendEmailForOptions = ( + opts: ResendEmailOptions, +): CreateEmailOptions => { const { to, from, @@ -17,16 +20,16 @@ const resendEmailForOptions = (opts: ResendEmailOptions) => { tags, } = opts; - return { + // Build base options without rendered outputs (react/html/text) + // CreateEmailOptions requires at least one of react, html, or text + const baseOptions = { to, from: from || VARIANT_TO_FROM_MAP[variant], - bcc: bcc, + subject: subject!, + bcc, // if replyTo is set to "noreply@dub.co", don't set replyTo // else set it to the value of replyTo or fallback to support@dub.co ...(replyTo === "noreply" ? {} : { replyTo: replyTo || "support@dub.co" }), - subject, - text, - react, scheduledAt, tags, ...(variant === "marketing" @@ -36,10 +39,20 @@ const resendEmailForOptions = (opts: ResendEmailOptions) => { "List-Unsubscribe": "https://app.dub.co/account/settings", }, } - : { - headers, - }), + : headers && { headers }), }; + + // Add render options (react, html, or text) - at least one must be present + // CreateEmailOptions requires at least one of react, html, or text + if (react) { + return { ...baseOptions, react }; + } + if (text) { + return { ...baseOptions, text }; + } + // If none of react, html, or text is provided, we need to ensure at least one is present + // This shouldn't happen in practice, but we'll default to an empty text + return { ...baseOptions, text: "" }; }; // Send email using Resend (Recommended for production)