Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

♻️ refactor: add support contacts to emails (#17177)

YuTengjing432fbdfa6483
diff --git a/apps/server/src/services/email/index.test.ts b/apps/server/src/services/email/index.test.ts
index ca4e177eb8f..2cf9d0aa33f 100644
--- a/apps/server/src/services/email/index.test.ts
+++ b/apps/server/src/services/email/index.test.ts
@@ -1,8 +1,14 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { EMAIL_SUPPORT_REPLY_TO } from '@/libs/email/support';
+
import { createEmailServiceImpl, EmailImplType } from './impls';
import { EmailService } from './index';
+vi.mock('@/envs/email', () => ({
+ emailEnv: { EMAIL_SERVICE_PROVIDER: undefined },
+}));
+
// Mock dependencies
vi.mock('./impls');
@@ -53,7 +59,9 @@ describe('EmailService', () => {
const result = await emailService.sendMail(payload);
- expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(payload);
+ expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(
+ EMAIL_SUPPORT_REPLY_TO ? { ...payload, replyTo: EMAIL_SUPPORT_REPLY_TO } : payload,
+ );
expect(result).toBe(mockResponse);
});
@@ -72,7 +80,9 @@ describe('EmailService', () => {
await emailService.sendMail(payload);
- expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(payload);
+ expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(
+ EMAIL_SUPPORT_REPLY_TO ? { ...payload, replyTo: EMAIL_SUPPORT_REPLY_TO } : payload,
+ );
});
it('should support attachments', async () => {
@@ -96,7 +106,9 @@ describe('EmailService', () => {
await emailService.sendMail(payload);
- expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(payload);
+ expect(mockEmailImpl.sendMail).toHaveBeenCalledWith(
+ EMAIL_SUPPORT_REPLY_TO ? { ...payload, replyTo: EMAIL_SUPPORT_REPLY_TO } : payload,
+ );
});
it('should support reply-to address', async () => {
diff --git a/apps/server/src/services/email/index.ts b/apps/server/src/services/email/index.ts
index 7a8a46c43c4..d929369ef99 100644
--- a/apps/server/src/services/email/index.ts
+++ b/apps/server/src/services/email/index.ts
@@ -1,4 +1,5 @@
import { emailEnv } from '@/envs/email';
+import { EMAIL_SUPPORT_REPLY_TO } from '@/libs/email/support';
import { type EmailPayload, type EmailResponse, type EmailServiceImpl } from './impls';
import { createEmailServiceImpl, EmailImplType } from './impls';
@@ -25,7 +26,9 @@ export class EmailService {
* Send an email
*/
async sendMail(payload: EmailPayload): Promise<EmailResponse> {
- return this.emailImpl.sendMail(payload);
+ const replyTo = payload.replyTo || EMAIL_SUPPORT_REPLY_TO;
+
+ return this.emailImpl.sendMail(replyTo ? { ...payload, replyTo } : payload);
}
/**
diff --git a/locales/en-US/notification.json b/locales/en-US/notification.json
index 544a92b6883..6d384e2a4e2 100644
--- a/locales/en-US/notification.json
+++ b/locales/en-US/notification.json
@@ -13,6 +13,8 @@
"credit_balance_low": "Your credit balance is running low — about {{balance}} in credits remaining. Turn on auto top-up so your balance refills automatically and your work is never interrupted.",
"credit_balance_low_action": "Set up auto top-up",
"credit_balance_low_title": "Your credit balance is running low",
+ "email.footer.contactSupport": "Contact support",
+ "email.footer.joinDiscord": "Join Discord",
"email.footer.manage": "Manage notifications",
"email.footer.preference": "You received this email because of your notification settings on LobeHub.",
"email.footer.system": "This is an important account notification from LobeHub.",
diff --git a/locales/zh-CN/notification.json b/locales/zh-CN/notification.json
index 4334ea7c4e9..045f03b4fca 100644
--- a/locales/zh-CN/notification.json
+++ b/locales/zh-CN/notification.json
@@ -13,6 +13,8 @@
"credit_balance_low": "您的积分余额即将用尽,当前约剩余 {{balance}} 的积分。建议开启自动充值,余额不足时自动续费,让你的工作不被中断。",
"credit_balance_low_action": "开启自动充值",
"credit_balance_low_title": "您的积分余额即将用尽",
+ "email.footer.contactSupport": "联系支持",
+ "email.footer.joinDiscord": "加入 Discord",
"email.footer.manage": "管理通知",
"email.footer.preference": "你收到这封邮件是因为你在 LobeHub 的通知设置。",
"email.footer.system": "这是一封来自 LobeHub 的重要账户通知。",
diff --git a/packages/business/const/src/branding.test.ts b/packages/business/const/src/branding.test.ts
new file mode 100644
index 00000000000..7e0cc052ffc
--- /dev/null
+++ b/packages/business/const/src/branding.test.ts
@@ -0,0 +1,9 @@
+import { describe, expect, it } from 'vitest';
+
+import { BRANDING_EMAIL } from './branding';
+
+describe('BRANDING_EMAIL', () => {
+ it('leaves Reply-To unset by default for self-hosted deployments', () => {
+ expect(BRANDING_EMAIL.replyTo).toBeUndefined();
+ });
+});
diff --git a/packages/business/const/src/branding.ts b/packages/business/const/src/branding.ts
index 8624df54e85..34a5cf94db0 100644
--- a/packages/business/const/src/branding.ts
+++ b/packages/business/const/src/branding.ts
@@ -31,6 +31,7 @@ export const FILE_URL = {
export const BRANDING_EMAIL = {
business: '[email protected]',
+ replyTo: undefined,
support: '[email protected]',
};
diff --git a/packages/locales/src/default/notification.ts b/packages/locales/src/default/notification.ts
index 8927f08f2d6..9c749faf476 100644
--- a/packages/locales/src/default/notification.ts
+++ b/packages/locales/src/default/notification.ts
@@ -16,6 +16,8 @@ export default {
'Your credit balance is running low — about {{balance}} in credits remaining. Turn on auto top-up so your balance refills automatically and your work is never interrupted.',
'credit_balance_low_action': 'Set up auto top-up',
'credit_balance_low_title': 'Your credit balance is running low',
+ 'email.footer.contactSupport': 'Contact support',
+ 'email.footer.joinDiscord': 'Join Discord',
'email.footer.manage': 'Manage notifications',
'email.footer.preference':
'You received this email because of your notification settings on LobeHub.',
diff --git a/src/libs/better-auth/email-templates/change-email.ts b/src/libs/better-auth/email-templates/change-email.ts
index 34357ad9dd8..b79175a8e95 100644
--- a/src/libs/better-auth/email-templates/change-email.ts
+++ b/src/libs/better-auth/email-templates/change-email.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Change email verification template
* Sent to users when they request to change their email address
@@ -94,6 +96,9 @@ export const getChangeEmailVerificationTemplate = (params: {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
© 2026 LobeHub. All rights reserved.
</p>
@@ -103,6 +108,6 @@ export const getChangeEmailVerificationTemplate = (params: {
</html>
`,
subject: 'Confirm Your New Email - LobeHub',
- text: `You requested to change your LobeHub account email. Please confirm by clicking this link: ${url}\n\nThis link will expire in ${expirationText}.\n\nIf you didn't request this change, you can safely ignore this email.`,
+ text: `You requested to change your LobeHub account email. Please confirm by clicking this link: ${url}\n\nThis link will expire in ${expirationText}.\n\nIf you didn't request this change, you can safely ignore this email.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/index.test.ts b/src/libs/better-auth/email-templates/index.test.ts
new file mode 100644
index 00000000000..ab5a4e5ed26
--- /dev/null
+++ b/src/libs/better-auth/email-templates/index.test.ts
@@ -0,0 +1,50 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ getChangeEmailVerificationTemplate,
+ getMagicLinkEmailTemplate,
+ getResetPasswordEmailTemplate,
+ getVerificationEmailTemplate,
+ getVerificationOTPEmailTemplate,
+ getWorkspaceInviteEmailTemplate,
+ getWorkspaceMemberRemovedEmailTemplate,
+} from './index';
+
+const templates = [
+ getChangeEmailVerificationTemplate({
+ expiresInSeconds: 3600,
+ url: 'https://example.com/change-email',
+ }),
+ getMagicLinkEmailTemplate({
+ expiresInSeconds: 600,
+ url: 'https://example.com/sign-in',
+ }),
+ getResetPasswordEmailTemplate({ url: 'https://example.com/reset-password' }),
+ getVerificationEmailTemplate({
+ expiresInSeconds: 3600,
+ url: 'https://example.com/verify-email',
+ }),
+ getVerificationOTPEmailTemplate({ expiresInSeconds: 600, otp: '123456' }),
+ getWorkspaceInviteEmailTemplate({
+ expiresInDays: 7,
+ role: 'member',
+ url: 'https://example.com/invite',
+ workspaceName: 'Example Workspace',
+ }),
+ getWorkspaceMemberRemovedEmailTemplate({
+ reason: 'removed_by_owner',
+ workspaceName: 'Example Workspace',
+ }),
+];
+
+describe('email templates', () => {
+ it.each(templates)(
+ 'includes support email and Discord links in HTML and plain text',
+ (template) => {
+ expect(template.html).toContain('href="mailto:[email protected]"');
+ expect(template.html).toContain('https://discord.gg/');
+ expect(template.text).toContain('[email protected]');
+ expect(template.text).toContain('https://discord.gg/');
+ },
+ );
+});
diff --git a/src/libs/better-auth/email-templates/magic-link.ts b/src/libs/better-auth/email-templates/magic-link.ts
index c5b55541eaa..366743cad1b 100644
--- a/src/libs/better-auth/email-templates/magic-link.ts
+++ b/src/libs/better-auth/email-templates/magic-link.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Magic link sign-in email template
* Sent when user requests passwordless login
@@ -84,6 +86,9 @@ export const getMagicLinkEmailTemplate = (params: { expiresInSeconds: number; ur
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
© ${new Date().getFullYear()} LobeHub. All rights reserved.
</p>
@@ -93,6 +98,6 @@ export const getMagicLinkEmailTemplate = (params: { expiresInSeconds: number; ur
</html>
`,
subject: 'Your LobeHub sign-in link',
- text: `Use this link to sign in: ${url}\n\nThis link expires in ${expirationText}.`,
+ text: `Use this link to sign in: ${url}\n\nThis link expires in ${expirationText}.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/reset-password.ts b/src/libs/better-auth/email-templates/reset-password.ts
index 15ebbbe68b1..8c5e51424f0 100644
--- a/src/libs/better-auth/email-templates/reset-password.ts
+++ b/src/libs/better-auth/email-templates/reset-password.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Password reset email template
* Sent to users when they request a password reset
@@ -77,6 +79,9 @@ export const getResetPasswordEmailTemplate = (params: { url: string }) => {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
© ${new Date().getFullYear()} LobeHub. All rights reserved.
</p>
@@ -86,6 +91,6 @@ export const getResetPasswordEmailTemplate = (params: { url: string }) => {
</html>
`,
subject: 'Reset Your Password - LobeHub',
- text: `Reset your password by clicking this link: ${url}`,
+ text: `Reset your password by clicking this link: ${url}\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/verification-otp.ts b/src/libs/better-auth/email-templates/verification-otp.ts
index 28b03b4b956..b9fefd8d927 100644
--- a/src/libs/better-auth/email-templates/verification-otp.ts
+++ b/src/libs/better-auth/email-templates/verification-otp.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Email OTP verification template for mobile
* Sent to users when they need to verify their email using OTP code
@@ -92,6 +94,9 @@ export const getVerificationOTPEmailTemplate = (params: {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
© 2026 LobeHub. All rights reserved.
</p>
@@ -101,6 +106,6 @@ export const getVerificationOTPEmailTemplate = (params: {
</html>
`,
subject: 'Verify Your Email - LobeHub',
- text: `Your verification code is: ${otp}\n\nThis code will expire in ${expirationText}.\n\nIf you didn't request this code, you can safely ignore this email.`,
+ text: `Your verification code is: ${otp}\n\nThis code will expire in ${expirationText}.\n\nIf you didn't request this code, you can safely ignore this email.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/verification.ts b/src/libs/better-auth/email-templates/verification.ts
index 5616f65570d..45040aeab83 100644
--- a/src/libs/better-auth/email-templates/verification.ts
+++ b/src/libs/better-auth/email-templates/verification.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Email verification template
* Sent to users when they sign up to verify their email address
@@ -94,6 +96,9 @@ export const getVerificationEmailTemplate = (params: {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
© 2026 LobeHub. All rights reserved.
</p>
@@ -103,6 +108,6 @@ export const getVerificationEmailTemplate = (params: {
</html>
`,
subject: 'Verify Your Email - LobeHub',
- text: `Please verify your email by clicking this link: ${url}\n\nThis link will expire in ${expirationText}.`,
+ text: `Please verify your email by clicking this link: ${url}\n\nThis link will expire in ${expirationText}.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/workspace-invite.ts b/src/libs/better-auth/email-templates/workspace-invite.ts
index 5ca952b3778..1e12b52bbf9 100644
--- a/src/libs/better-auth/email-templates/workspace-invite.ts
+++ b/src/libs/better-auth/email-templates/workspace-invite.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
/**
* Workspace invitation email template
* Sent when a workspace owner invites someone (by email) to join their workspace.
@@ -94,6 +96,9 @@ export const getWorkspaceInviteEmailTemplate = (params: {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
If you weren't expecting this invitation, you can safely ignore this email.
</p>
@@ -103,6 +108,6 @@ export const getWorkspaceInviteEmailTemplate = (params: {
</html>
`,
subject,
- text: `${inviterByline} has invited you to join the "${workspaceName}" workspace on LobeHub as ${roleLabel}.\n\nAccept the invitation: ${url}\n\nThis invitation will expire in ${expiresInDays} day${expiresInDays > 1 ? 's' : ''}.\n\nIf you weren't expecting this invitation, you can safely ignore this email.`,
+ text: `${inviterByline} has invited you to join the "${workspaceName}" workspace on LobeHub as ${roleLabel}.\n\nAccept the invitation: ${url}\n\nThis invitation will expire in ${expiresInDays} day${expiresInDays > 1 ? 's' : ''}.\n\nIf you weren't expecting this invitation, you can safely ignore this email.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/better-auth/email-templates/workspace-member-removed.ts b/src/libs/better-auth/email-templates/workspace-member-removed.ts
index 92497d2fa09..f7a0b5aeb58 100644
--- a/src/libs/better-auth/email-templates/workspace-member-removed.ts
+++ b/src/libs/better-auth/email-templates/workspace-member-removed.ts
@@ -1,3 +1,5 @@
+import { getEmailSupportHtml, getEmailSupportText } from '@/libs/email/support';
+
export const getWorkspaceMemberRemovedEmailTemplate = (params: {
reason: 'downgrade' | 'removed_by_owner';
workspaceName: string;
@@ -75,6 +77,9 @@ export const getWorkspaceMemberRemovedEmailTemplate = (params: {
<!-- Footer -->
<div style="text-align: center; margin-top: 32px;">
+ <p style="font-size: 13px; margin: 0 0 8px 0;">
+ ${getEmailSupportHtml()}
+ </p>
<p style="color: #a1a1aa; font-size: 13px; margin: 0;">
This is an automated message from LobeHub.
</p>
@@ -85,7 +90,7 @@ export const getWorkspaceMemberRemovedEmailTemplate = (params: {
`,
subject,
text: isDowngrade
- ? `The workspace "${workspaceName}" has been downgraded, and all team members have been removed as a result. Your personal data and workspaces are not affected. If you believe this was a mistake, please contact the workspace owner.`
- : `The owner of "${workspaceName}" has removed you from the workspace. Your personal data and workspaces are not affected. If you believe this was a mistake, please contact the workspace owner.`,
+ ? `The workspace "${workspaceName}" has been downgraded, and all team members have been removed as a result. Your personal data and workspaces are not affected. If you believe this was a mistake, please contact the workspace owner.\n\n${getEmailSupportText()}`
+ : `The owner of "${workspaceName}" has removed you from the workspace. Your personal data and workspaces are not affected. If you believe this was a mistake, please contact the workspace owner.\n\n${getEmailSupportText()}`,
};
};
diff --git a/src/libs/email/support.test.ts b/src/libs/email/support.test.ts
new file mode 100644
index 00000000000..789aaac0a40
--- /dev/null
+++ b/src/libs/email/support.test.ts
@@ -0,0 +1,28 @@
+import { describe, expect, it } from 'vitest';
+
+import { EMAIL_SUPPORT_ADDRESS, getEmailSupportHtml, getEmailSupportText } from './support';
+
+describe('email support helpers', () => {
+ it('renders actionable support links for HTML and plain-text emails', () => {
+ const html = getEmailSupportHtml();
+ const text = getEmailSupportText();
+
+ expect(EMAIL_SUPPORT_ADDRESS).toBe('[email protected]');
+ expect(html).toContain('href="mailto:[email protected]"');
+ expect(html).toContain('https://discord.gg/');
+ expect(text).toContain('[email protected]');
+ expect(text).toContain('https://discord.gg/');
+ });
+
+ it('escapes localized labels before rendering HTML', () => {
+ const html = getEmailSupportHtml({
+ contactSupport: '<script>alert("support")</script>',
+ joinDiscord: '<strong>Discord</strong>',
+ });
+
+ expect(html).not.toContain('<script>');
+ expect(html).not.toContain('<strong>');
+ expect(html).toContain('&lt;script&gt;');
+ expect(html).toContain('&lt;strong&gt;');
+ });
+});
diff --git a/src/libs/email/support.ts b/src/libs/email/support.ts
new file mode 100644
index 00000000000..a06133c57dc
--- /dev/null
+++ b/src/libs/email/support.ts
@@ -0,0 +1,38 @@
+import { BRANDING_EMAIL, SOCIAL_URL } from '@lobechat/business-const';
+
+interface EmailSupportCopy {
+ contactSupport?: string;
+ joinDiscord?: string;
+}
+
+const DEFAULT_SUPPORT_COPY = {
+ contactSupport: 'Contact support',
+ joinDiscord: 'Join Discord',
+} satisfies Required<EmailSupportCopy>;
+
+const escapeHtml = (value: string) =>
+ value
+ .replaceAll('&', '&amp;')
+ .replaceAll('<', '&lt;')
+ .replaceAll('>', '&gt;')
+ .replaceAll('"', '&quot;')
+ .replaceAll("'", '&#39;');
+
+export const EMAIL_SUPPORT_ADDRESS = BRANDING_EMAIL.support;
+export const EMAIL_SUPPORT_REPLY_TO = BRANDING_EMAIL.replyTo;
+
+export const getEmailSupportHtml = ({
+ contactSupport = DEFAULT_SUPPORT_COPY.contactSupport,
+ joinDiscord = DEFAULT_SUPPORT_COPY.joinDiscord,
+}: EmailSupportCopy = {}) => {
+ const supportEmail = escapeHtml(EMAIL_SUPPORT_ADDRESS);
+ const discordUrl = escapeHtml(SOCIAL_URL.discord);
+
+ return `<a href="mailto:${supportEmail}" style="color: #6b7280; text-decoration: underline;">${escapeHtml(contactSupport)}</a><span style="color: #a1a1aa;"> · </span><a href="${discordUrl}" target="_blank" rel="noopener noreferrer" style="color: #6b7280; text-decoration: underline;">${escapeHtml(joinDiscord)}</a>`;
+};
+
+export const getEmailSupportText = ({
+ contactSupport = DEFAULT_SUPPORT_COPY.contactSupport,
+ joinDiscord = DEFAULT_SUPPORT_COPY.joinDiscord,
+}: EmailSupportCopy = {}) =>
+ `${contactSupport}: ${EMAIL_SUPPORT_ADDRESS} | ${joinDiscord}: ${SOCIAL_URL.discord}`;