feat: hide send mail UI when not configured (#827)

- Add isSendMailEnabled and isAnySendMailEnabled functions in common.ts
- Return enableSendMail field in /open_api/settings
- Hide sendmail tab, sendbox tab, and reply button when send mail is not configured
- Check RESEND_TOKEN, SMTP_CONFIG, and SEND_MAIL binding per domain

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Dream Hunter
2026-02-01 23:37:51 +08:00
committed by GitHub
parent e4b6c82e92
commit 0f418d7e94
4 changed files with 39 additions and 4 deletions

View File

@@ -34,6 +34,7 @@ export const useGlobalState = createGlobalState(
cfTurnstileSiteKey: '',
enableWebhook: false,
isS3Enabled: false,
enableSendMail: false,
showGithub: true,
disableAdminPasswordCheck: false,
enableAddressPassword: false,

View File

@@ -156,15 +156,15 @@ onMounted(() => {
</n-button>
</n-input-group>
</div>
<MailBox :key="mailBoxKey" :showEMailTo="false" :showReply="true" :showSaveS3="openSettings.isS3Enabled"
<MailBox :key="mailBoxKey" :showEMailTo="false" :showReply="openSettings.enableSendMail" :showSaveS3="openSettings.isS3Enabled"
:saveToS3="saveToS3" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
:fetchMailData="fetchMailData" :deleteMail="deleteMail" :showFilterInput="true" />
</n-tab-pane>
<n-tab-pane name="sendbox" :tab="t('sendbox')">
<n-tab-pane v-if="openSettings.enableSendMail" name="sendbox" :tab="t('sendbox')">
<SendBox :fetchMailData="fetchSenboxData" :enableUserDeleteEmail="openSettings.enableUserDeleteEmail"
:deleteMail="deleteSenboxMail" />
</n-tab-pane>
<n-tab-pane name="sendmail" :tab="t('sendmail')">
<n-tab-pane v-if="openSettings.enableSendMail" name="sendmail" :tab="t('sendmail')">
<SendMail />
</n-tab-pane>
<n-tab-pane name="accountSettings" :tab="t('accountSettings')">

View File

@@ -3,6 +3,7 @@ import { Hono } from 'hono'
import utils from './utils';
import { CONSTANTS } from './constants';
import { isS3Enabled } from './mails_api/s3_attachment';
import { isAnySendMailEnabled } from './common';
const api = new Hono<HonoCustomType>
@@ -38,6 +39,7 @@ api.get('/open_api/settings', async (c) => {
"cfTurnstileSiteKey": c.env.CF_TURNSTILE_SITE_KEY,
"enableWebhook": utils.getBooleanValue(c.env.ENABLE_WEBHOOK),
"isS3Enabled": isS3Enabled(c),
"enableSendMail": isAnySendMailEnabled(c),
"version": CONSTANTS.VERSION,
"showGithub": !utils.getBooleanValue(c.env.DISABLE_SHOW_GITHUB),
"disableAdminPasswordCheck": utils.getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK),

View File

@@ -1,7 +1,8 @@
import { Context } from 'hono';
import { Jwt } from 'hono/utils/jwt'
import { WorkerMailerOptions } from 'worker-mailer';
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword } from './utils';
import { getBooleanValue, getDomains, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue } from './utils';
import { unbindTelegramByAddress } from './telegram_api/common';
import { CONSTANTS } from './constants';
import { AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
@@ -9,6 +10,37 @@ import i18n from './i18n';
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
/**
* Check if send mail is enabled for a specific domain
*/
export const isSendMailEnabled = (
c: Context<HonoCustomType>,
mailDomain: string
): boolean => {
// Check resend token for domain or global
const resendEnabled = c.env.RESEND_TOKEN || c.env[
`RESEND_TOKEN_${mailDomain.replace(/\./g, "_").toUpperCase()}`
];
if (resendEnabled) return true;
// Check SMTP config for domain
const smtpConfigMap = getJsonObjectValue<Record<string, WorkerMailerOptions>>(c.env.SMTP_CONFIG);
if (smtpConfigMap && smtpConfigMap[mailDomain]) return true;
// Check SEND_MAIL binding
if (c.env.SEND_MAIL) return true;
return false;
}
/**
* Check if send mail is enabled for any configured domain
*/
export const isAnySendMailEnabled = (c: Context<HonoCustomType>): boolean => {
const domains = getDomains(c);
return domains.some(domain => isSendMailEnabled(c, domain));
}
export const generateRandomName = (c: Context<HonoCustomType>): string => {
// name min length min 1
const minLength = Math.max(