Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Skip reserved test domains in Resend (#4481)

Pedro Ladeirad585c3570ba8
diff --git a/packages/email/src/send-via-resend.ts b/packages/email/src/send-via-resend.ts
index aaf6a4c838..d26014bb1c 100644
--- a/packages/email/src/send-via-resend.ts
+++ b/packages/email/src/send-via-resend.ts
@@ -3,6 +3,35 @@ import { resend } from "./resend";
import { VARIANT_TO_FROM_MAP } from "./resend/constants";
import { ResendBulkEmailOptions, ResendEmailOptions } from "./resend/types";
+// Resend 422s reserved test domains:
+// https://resend.com/docs/knowledge-base/what-email-addresses-to-use-for-testing
+const RESEND_BLOCKED_DOMAINS = [
+ "example.com",
+ "example.net",
+ "example.org",
+ "test.com",
+] as const;
+
+const isResendBlockedRecipient = (to: string) => {
+ const domain = to.toLowerCase().trim().split("@").at(1);
+ if (!domain) return false;
+
+ return RESEND_BLOCKED_DOMAINS.some(
+ (blocked) => domain === blocked || domain.endsWith(`.${blocked}`),
+ );
+};
+
+// Keep batch cardinality so callers can zip Resend IDs by index.
+// [email protected] is a Resend test sink (no real inbox).
+const rewriteBlockedRecipient = (to: string) => {
+ if (!isResendBlockedRecipient(to)) return to;
+
+ const username = to.toLowerCase().trim().split("@").at(0) || "unknown";
+ const rewritten = `delivered+${username}@resend.dev`;
+ console.info(`Rewriting reserved Resend recipient ${to} → ${rewritten}`);
+ return rewritten;
+};
+
const resendEmailForOptions = (
opts: ResendEmailOptions,
): CreateEmailOptions => {
@@ -27,7 +56,7 @@ const resendEmailForOptions = (
// Build base options without rendered outputs (react/text)
// CreateEmailOptions requires at least one of react or text
const baseOptions = {
- to: isPreviewEnv ? "[email protected]" : to,
+ to: isPreviewEnv ? "[email protected]" : rewriteBlockedRecipient(to),
from: from || VARIANT_TO_FROM_MAP[variant],
subject: `${subject}${isPreviewEnv && gitBranch ? ` [${gitBranch}]` : ""}`,
bcc,