Skip to content

Commit 2e77d46

Browse files
authored
feat(email): add customizable "FROM" email for resend (#447)
* add customizable from email on resend via envvar * use existing getBaseDomain utility
1 parent a94f617 commit 2e77d46

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

apps/sim/app/api/help/route.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Resend } from 'resend'
33
import { z } from 'zod'
44
import { env } from '@/lib/env'
55
import { createLogger } from '@/lib/logs/console-logger'
6+
import { getBaseDomain } from '@/lib/urls/utils'
67

78
const resend = env.RESEND_API_KEY ? new Resend(env.RESEND_API_KEY) : null
89
const logger = createLogger('HelpAPI')
@@ -98,8 +99,8 @@ ${message}
9899

99100
// Send email using Resend
100101
const { data, error } = await resend.emails.send({
101-
from: 'Sim Studio <noreply@simstudio.ai>',
102-
to: ['help@simstudio.ai'],
102+
from: `Sim Studio <noreply@${getBaseDomain()}>`,
103+
to: [`help@${getBaseDomain()}`],
103104
subject: `[${type.toUpperCase()}] ${subject}`,
104105
replyTo: email,
105106
text: emailText,
@@ -121,7 +122,7 @@ ${message}
121122
// Send confirmation email to the user
122123
await resend.emails
123124
.send({
124-
from: 'Sim Studio <noreply@simstudio.ai>',
125+
from: `Sim Studio <noreply@${getBaseDomain()}>`,
125126
to: [email],
126127
subject: `Your ${type} request has been received: ${subject}`,
127128
text: `
@@ -137,7 +138,7 @@ ${images.length > 0 ? `You attached ${images.length} image(s).` : ''}
137138
Best regards,
138139
The Sim Studio Team
139140
`,
140-
replyTo: 'help@simstudio.ai',
141+
replyTo: `help@${getBaseDomain()}`,
141142
})
142143
.catch((err) => {
143144
logger.warn(`[${requestId}] Failed to send confirmation email`, err)

apps/sim/app/api/workspaces/invitations/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { WorkspaceInvitationEmail } from '@/components/emails/workspace-invitati
77
import { getSession } from '@/lib/auth'
88
import { env } from '@/lib/env'
99
import { createLogger } from '@/lib/logs/console-logger'
10+
import { getBaseDomain } from '@/lib/urls/utils'
1011
import { db } from '@/db'
1112
import { user, workspace, workspaceInvitation, workspaceMember } from '@/db/schema'
1213

@@ -228,7 +229,7 @@ async function sendInvitationEmail({
228229
}
229230

230231
await resend.emails.send({
231-
from: 'noreply@simstudio.ai',
232+
from: `noreply@${getBaseDomain()}`,
232233
to,
233234
subject: `You've been invited to join "${workspaceName}" on Sim Studio`,
234235
html: emailHtml,

apps/sim/lib/auth.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { createLogger } from '@/lib/logs/console-logger'
1717
import { db } from '@/db'
1818
import * as schema from '@/db/schema'
1919
import { env } from './env'
20+
import { getBaseDomain } from './urls/utils'
2021

2122
const logger = createLogger('Auth')
2223

@@ -145,7 +146,7 @@ export const auth = betterAuth({
145146
const html = await renderPasswordResetEmail(username, url)
146147

147148
const result = await resend.emails.send({
148-
from: 'Sim Studio <team@simstudio.ai>',
149+
from: `Sim Studio <team@${getBaseDomain()}>`,
149150
to: user.email,
150151
subject: getEmailSubject('reset-password'),
151152
html,
@@ -187,7 +188,7 @@ export const auth = betterAuth({
187188

188189
// In production, send an actual email
189190
const result = await resend.emails.send({
190-
from: 'Sim Studio <onboarding@simstudio.ai>',
191+
from: `Sim Studio <onboarding@${getBaseDomain()}>`,
191192
to: data.email,
192193
subject: getEmailSubject(data.type),
193194
html,
@@ -1077,7 +1078,7 @@ export const auth = betterAuth({
10771078
)
10781079

10791080
await resend.emails.send({
1080-
from: 'Sim Studio <team@simstudio.ai>',
1081+
from: `Sim Studio <team@${getBaseDomain()}>`,
10811082
to: invitation.email,
10821083
subject: `${inviterName} has invited you to join ${organization.name} on Sim Studio`,
10831084
html,

apps/sim/lib/mailer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Resend } from 'resend'
22
import { createLogger } from '@/lib/logs/console-logger'
33
import { env } from './env'
4+
import { getBaseDomain } from './urls/utils'
45

56
interface EmailOptions {
67
to: string
@@ -41,7 +42,7 @@ export async function sendEmail({
4142
from,
4243
}: EmailOptions): Promise<SendEmailResult> {
4344
try {
44-
const senderEmail = from || 'noreply@simstudio.ai'
45+
const senderEmail = from || `noreply@${getBaseDomain()}`
4546

4647
if (!resend) {
4748
logger.info('Email not sent (Resend not configured):', {
@@ -89,7 +90,7 @@ export async function sendBatchEmails({
8990
emails,
9091
}: BatchEmailOptions): Promise<BatchSendEmailResult> {
9192
try {
92-
const senderEmail = 'noreply@simstudio.ai'
93+
const senderEmail = `noreply@${getBaseDomain()}`
9394
const results: SendEmailResult[] = []
9495

9596
if (!resend) {

0 commit comments

Comments
 (0)