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.

Add mail.dub.co for notifications

Steven Tey9138e0cc5799
diff --git a/apps/web/app/api/cron/domains/verify/utils.ts b/apps/web/app/api/cron/domains/verify/utils.ts
index 3c639bda9a..871565ed9a 100644
--- a/apps/web/app/api/cron/domains/verify/utils.ts
+++ b/apps/web/app/api/cron/domains/verify/utils.ts
@@ -138,6 +138,7 @@ export const handleDomainUpdates = async ({
domain,
workspaceSlug,
}),
+ variant: "notifications",
}),
),
),
@@ -200,12 +201,12 @@ const sendDomainInvalidEmail = async ({
subject: `Your domain ${domain} needs to be configured`,
email,
react: InvalidDomain({
- appDomain: process.env.NEXT_PUBLIC_APP_DOMAIN as string,
email,
domain,
workspaceSlug,
invalidDays,
}),
+ variant: "notifications",
}),
),
),
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index 1477498d07..523cc149ff 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -173,6 +173,7 @@ export const updateUsage = async () => {
createdLinks: workspace.linksUsage,
topLinks: topFiveLinks,
}),
+ variant: "notifications",
}),
);
}),
diff --git a/apps/web/app/api/stripe/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/webhook/checkout-session-completed.ts
index 661caec9bc..91e278400c 100644
--- a/apps/web/app/api/stripe/webhook/checkout-session-completed.ts
+++ b/apps/web/app/api/stripe/webhook/checkout-session-completed.ts
@@ -109,7 +109,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
email: user.email as string,
plan: plan.name,
}),
- marketing: true,
+ variant: "marketing",
}),
);
}),
diff --git a/apps/web/lib/api/partners/notify-partner-application.ts b/apps/web/lib/api/partners/notify-partner-application.ts
index 7a1dc015e8..94719ca9dc 100644
--- a/apps/web/lib/api/partners/notify-partner-application.ts
+++ b/apps/web/lib/api/partners/notify-partner-application.ts
@@ -64,6 +64,7 @@ export async function notifyPartnerApplication({
slug: project.slug,
},
}),
+ variant: "notifications",
}),
),
),
diff --git a/apps/web/lib/api/partners/notify-partner-sale.ts b/apps/web/lib/api/partners/notify-partner-sale.ts
index cd7f538b49..43b8b63d19 100644
--- a/apps/web/lib/api/partners/notify-partner-sale.ts
+++ b/apps/web/lib/api/partners/notify-partner-sale.ts
@@ -101,12 +101,12 @@ export async function notifyPartnerSale({
? [
sendEmail({
subject: "You just made a sale via Dub Partners!",
- from: "Dub Partners <[email protected]>",
email: partner.email!,
react: NewSaleAlertPartner({
email: partner.email!,
...data,
}),
+ variant: "notifications",
}),
]
: []),
@@ -114,7 +114,6 @@ export async function notifyPartnerSale({
limiter.schedule(() =>
sendEmail({
subject: `New commission for ${partner.name}`,
- from: "Dub Partners <[email protected]>",
email: user.email!,
react: NewSaleAlertProgramOwner({
...data,
@@ -124,6 +123,7 @@ export async function notifyPartnerSale({
},
workspace,
}),
+ variant: "notifications",
}),
),
),
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index a5c46a0676..01037a2e31 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -523,7 +523,7 @@ export const authOptions: NextAuthOptions = {
}),
// send the welcome email 5 minutes after the user signed up
scheduledAt: new Date(Date.now() + 5 * 60 * 1000).toISOString(),
- marketing: true,
+ variant: "marketing",
}),
trackLead(user),
]),
diff --git a/packages/email/src/index.ts b/packages/email/src/index.ts
index 006c424bc0..226041536b 100644
--- a/packages/email/src/index.ts
+++ b/packages/email/src/index.ts
@@ -1,34 +1,10 @@
-import { CreateEmailOptions } from "resend";
import { resend, sendEmailViaResend } from "./resend";
+import { ResendEmailOptions } from "./resend/types";
import { sendViaNodeMailer } from "./send-via-nodemailer";
-export const sendEmail = async ({
- email,
- replyTo,
- subject,
- from,
- bcc,
- text,
- react,
- scheduledAt,
- marketing,
-}: Omit<CreateEmailOptions, "to" | "from"> & {
- email: string;
- from?: string;
- marketing?: boolean;
-}) => {
+export const sendEmail = async (opts: ResendEmailOptions) => {
if (resend) {
- return await sendEmailViaResend({
- email,
- replyTo,
- subject,
- from,
- bcc,
- text,
- react,
- scheduledAt,
- marketing,
- });
+ return await sendEmailViaResend(opts);
}
// Fallback to SMTP if Resend is not configured
@@ -37,6 +13,7 @@ export const sendEmail = async ({
);
if (smtpConfigured) {
+ const { email, subject, text, react } = opts;
return await sendViaNodeMailer({
email,
subject,
diff --git a/packages/email/src/resend/index.ts b/packages/email/src/resend/index.ts
index 48091d04d8..54dbe21092 100644
--- a/packages/email/src/resend/index.ts
+++ b/packages/email/src/resend/index.ts
@@ -1,25 +1,18 @@
-import { CreateEmailOptions, Resend } from "resend";
+import { Resend } from "resend";
+import { ResendEmailOptions } from "./types";
export const resend = process.env.RESEND_API_KEY
? new Resend(process.env.RESEND_API_KEY)
: null;
+const VARIANT_TO_FROM_MAP = {
+ primary: "Dub.co <[email protected]>",
+ notifications: "Dub.co <[email protected]>",
+ marketing: "Steven from Dub.co <[email protected]>",
+};
+
// Send email using Resend (Recommended for production)
-export const sendEmailViaResend = async ({
- email,
- replyTo,
- subject,
- from,
- bcc,
- text,
- react,
- scheduledAt,
- marketing,
-}: Omit<CreateEmailOptions, "to" | "from"> & {
- email: string;
- from?: string;
- marketing?: boolean;
-}) => {
+export const sendEmailViaResend = async (opts: ResendEmailOptions) => {
if (!resend) {
console.info(
"RESEND_API_KEY is not set in the .env. Skipping sending email.",
@@ -27,20 +20,28 @@ export const sendEmailViaResend = async ({
return;
}
+ const {
+ email,
+ from,
+ variant = "primary",
+ bcc,
+ replyTo,
+ subject,
+ text,
+ react,
+ scheduledAt,
+ } = opts;
+
return await resend.emails.send({
to: email,
- from:
- from ||
- (marketing
- ? "Steven from Dub.co <[email protected]>"
- : "Dub.co <[email protected]>"),
+ from: from || VARIANT_TO_FROM_MAP[variant],
bcc: bcc,
- replyTo,
+ replyTo: replyTo || "[email protected]",
subject,
text,
react,
scheduledAt,
- ...(marketing && {
+ ...(variant === "marketing" && {
headers: {
"List-Unsubscribe": "https://app.dub.co/account/settings",
},
diff --git a/packages/email/src/resend/types.ts b/packages/email/src/resend/types.ts
new file mode 100644
index 0000000000..63b35317a9
--- /dev/null
+++ b/packages/email/src/resend/types.ts
@@ -0,0 +1,8 @@
+import { CreateEmailOptions } from "resend";
+
+export interface ResendEmailOptions
+ extends Omit<CreateEmailOptions, "to" | "from"> {
+ email: string;
+ from?: string;
+ variant?: "primary" | "notifications" | "marketing";
+}
diff --git a/packages/email/src/templates/domain-deleted.tsx b/packages/email/src/templates/domain-deleted.tsx
index 7e592cb913..4a452a514e 100644
--- a/packages/email/src/templates/domain-deleted.tsx
+++ b/packages/email/src/templates/domain-deleted.tsx
@@ -69,7 +69,10 @@ export function DomainDeleted({
If you did not want to keep using this domain on Dub.co anyway,
you can simply ignore this email.
</Text>
- <Footer email={email} />
+ <Footer
+ email={email}
+ notificationSettingsUrl={`https://app.dub.co/${workspaceSlug}/settings/notifications`}
+ />
</Container>
</Body>
</Tailwind>
diff --git a/packages/email/src/templates/invalid-domain.tsx b/packages/email/src/templates/invalid-domain.tsx
index a798fc4c4b..ec7fdfa4fa 100644
--- a/packages/email/src/templates/invalid-domain.tsx
+++ b/packages/email/src/templates/invalid-domain.tsx
@@ -19,16 +19,12 @@ export function InvalidDomain({
domain = "dub.sh",
workspaceSlug = "dub",
invalidDays = 14,
- appDomain = "dub.co",
}: {
email: string;
domain: string;
workspaceSlug: string;
invalidDays: number;
- appDomain: string;
}): JSX.Element {
- const notificationSettingsUrl = `https://app.${appDomain}/${workspaceSlug}/settings/notifications`;
-
return (
<Html>
<Head />
@@ -88,7 +84,7 @@ export function InvalidDomain({
</Text>
<Footer
email={email}
- notificationSettingsUrl={notificationSettingsUrl}
+ notificationSettingsUrl={`https://app.dub.co/${workspaceSlug}/settings/notifications`}
/>
</Container>
</Body>
diff --git a/packages/email/src/templates/new-sale-alert-program-owner.tsx b/packages/email/src/templates/new-sale-alert-program-owner.tsx
index 0e1d80fa5e..69a38aa279 100644
--- a/packages/email/src/templates/new-sale-alert-program-owner.tsx
+++ b/packages/email/src/templates/new-sale-alert-program-owner.tsx
@@ -202,7 +202,10 @@ export function NewSaleAlertProgramOwner({
</Link>
</Text>
- <Footer email={user.email} />
+ <Footer
+ email={user.email}
+ notificationSettingsUrl={notificationPreferencesLink}
+ />
</Container>
</Body>
</Tailwind>
diff --git a/packages/email/src/templates/partner-application-received.tsx b/packages/email/src/templates/partner-application-received.tsx
index a369ec6502..d9ccf30f10 100644
--- a/packages/email/src/templates/partner-application-received.tsx
+++ b/packages/email/src/templates/partner-application-received.tsx
@@ -160,7 +160,10 @@ export function PartnerApplicationReceived({
</Section>
</Container>
- <Footer email={email} />
+ <Footer
+ email={email}
+ notificationSettingsUrl={`https://app.dub.co/${workspace.slug}/settings/notifications`}
+ />
</Container>
</Body>
</Tailwind>