Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions packages/email/src/send-via-resend.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 "[email protected]", don't set replyTo
// else set it to the value of replyTo or fallback to [email protected]
...(replyTo === "noreply" ? {} : { replyTo: replyTo || "[email protected]" }),
subject,
text,
react,
scheduledAt,
tags,
...(variant === "marketing"
Expand All @@ -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)
Expand Down