Compare commits

...
4 Commits
Author SHA1 Message Date
Dream HunterandClaude 2bbde15f53 feat: add clear inbox and sent items functionality (#720)
- Add clear inbox/sent items APIs for users and admins
- Implement ENABLE_USER_DELETE_EMAIL permission checks
- Fix multilingual support for success messages
- Update Vue to 3.5.21 and Wrangler to 4.34.0
- Add UI components for clearing email data in account settings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-05 20:43:28 +08:00
Dream HunterandClaude 37cf0776b5 feat: enhance webhook security with configurable allow list (#719)
- Add enableAllowList flag to webhook settings for flexible access control
- Update frontend UI with toggle switch and improved user experience
- Maintain backward compatibility with default allow-all behavior
- Add input validation hints and better form controls across admin panels

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-05 17:24:30 +08:00
Dream HunterandClaude 3fbace871c feat: add var DISABLE_CUSTOM_ADDRESS_NAME and CREATE_ADDRESS_DEFAULT_… (#717)
* feat: add var DISABLE_CUSTOM_ADDRESS_NAME and CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST

* fix: enhance input validation with trim() for address creation

- Add trim() handling in newAddress() function to prevent whitespace issues
- Add trim() handling for address prefixes to ensure consistent formatting
- Add trim() handling in Telegram API address parsing for robustness
- Prevents edge cases with whitespace-only or padded input strings

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-09-04 21:04:42 +08:00
Dream Hunter 648e9f7adf feat: add simplemode button at index (#714) 2025-08-27 20:22:52 +08:00
36 changed files with 1893 additions and 1501 deletions
+8 -1
View File
@@ -1,7 +1,14 @@
<!-- markdownlint-disable-file MD004 MD024 MD034 MD036 --> <!-- markdownlint-disable-file MD004 MD024 MD034 MD036 -->
# CHANGE LOG # CHANGE LOG
## main(v1.0.4) ## main(v1.0.5)
- feat: 新增 `DISABLE_CUSTOM_ADDRESS_NAME` 配置: 禁用自定义邮箱地址名称功能
- feat: 新增 `CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST` 配置: 创建地址时优先使用第一个域名
- feat: |UI| 主页增加进入极简模式按钮
- feat: |Webhook| 增加白名单开关功能,支持灵活控制访问权限
## v1.0.4
- feat: |UI| 优化极简模式主页, 增加全部邮件页面功能(删除/下载/附件/...), 可在 `外观` 中切换 - feat: |UI| 优化极简模式主页, 增加全部邮件页面功能(删除/下载/附件/...), 可在 `外观` 中切换
- feat: admin 账号设置页面增加 `邮件转发规则` 配置 - feat: admin 账号设置页面增加 `邮件转发规则` 配置
+2 -2
View File
@@ -1,5 +1,5 @@
<!-- markdownlint-disable-file MD033 MD045 --> <!-- markdownlint-disable-file MD033 MD045 -->
# 🚀 Cloudflare 临时邮箱 - 免费搭建临时邮件服务 # Cloudflare 临时邮箱 - 免费搭建临时邮件服务
<p align="center"> <p align="center">
<a href="https://temp-mail-docs.awsl.uk" target="_blank"> <a href="https://temp-mail-docs.awsl.uk" target="_blank">
@@ -81,7 +81,7 @@
<details open> <details open>
<summary>📖 目录(点击收缩/展开)</summary> <summary>📖 目录(点击收缩/展开)</summary>
- [🚀 Cloudflare 临时邮箱 - 免费搭建临时邮件服务](#-cloudflare-临时邮箱---免费搭建临时邮件服务) - [Cloudflare 临时邮箱 - 免费搭建临时邮件服务](#cloudflare-临时邮箱---免费搭建临时邮件服务)
- [📚 部署文档 - 快速开始](#-部署文档---快速开始) - [📚 部署文档 - 快速开始](#-部署文档---快速开始)
- [📝 更新日志](#-更新日志) - [📝 更新日志](#-更新日志)
- [🎯 在线体验](#-在线体验) - [🎯 在线体验](#-在线体验)
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "cloudflare_temp_email", "name": "cloudflare_temp_email",
"version": "1.0.4", "version": "1.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
@@ -30,7 +30,7 @@
"naive-ui": "^2.42.0", "naive-ui": "^2.42.0",
"postal-mime": "^2.4.4", "postal-mime": "^2.4.4",
"vooks": "^0.2.12", "vooks": "^0.2.12",
"vue": "^3.5.19", "vue": "^3.5.21",
"vue-clipboard3": "^2.0.0", "vue-clipboard3": "^2.0.0",
"vue-i18n": "^11.1.11", "vue-i18n": "^11.1.11",
"vue-router": "^4.5.1" "vue-router": "^4.5.1"
@@ -47,7 +47,7 @@
"vite-plugin-wasm": "^3.5.0", "vite-plugin-wasm": "^3.5.0",
"workbox-build": "^7.3.0", "workbox-build": "^7.3.0",
"workbox-window": "^7.3.0", "workbox-window": "^7.3.0",
"wrangler": "^4.32.0" "wrangler": "^4.34.0"
}, },
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39" "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
} }
+346 -336
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -78,6 +78,7 @@ const getOpenSettings = async (message, notification) => {
adminContact: res["adminContact"] || "", adminContact: res["adminContact"] || "",
enableUserCreateEmail: res["enableUserCreateEmail"] || false, enableUserCreateEmail: res["enableUserCreateEmail"] || false,
disableAnonymousUserCreateEmail: res["disableAnonymousUserCreateEmail"] || false, disableAnonymousUserCreateEmail: res["disableAnonymousUserCreateEmail"] || false,
disableCustomAddressName: res["disableCustomAddressName"] || false,
enableUserDeleteEmail: res["enableUserDeleteEmail"] || false, enableUserDeleteEmail: res["enableUserDeleteEmail"] || false,
enableAutoReply: res["enableAutoReply"] || false, enableAutoReply: res["enableAutoReply"] || false,
enableIndexAbout: res["enableIndexAbout"] || false, enableIndexAbout: res["enableIndexAbout"] || false,
+1
View File
@@ -22,6 +22,7 @@ export const useGlobalState = createGlobalState(
adminContact: '', adminContact: '',
enableUserCreateEmail: false, enableUserCreateEmail: false,
disableAnonymousUserCreateEmail: false, disableAnonymousUserCreateEmail: false,
disableCustomAddressName: false,
enableUserDeleteEmail: false, enableUserDeleteEmail: false,
enableAutoReply: false, enableAutoReply: false,
enableIndexAbout: false, enableIndexAbout: false,
+15 -1
View File
@@ -5,6 +5,8 @@ import { useRoute } from 'vue-router'
import { useGlobalState } from '../store' import { useGlobalState } from '../store'
import { api } from '../api' import { api } from '../api'
import { useIsMobile } from '../utils/composables'
import { FullscreenExitOutlined } from '@vicons/material'
import AddressBar from './index/AddressBar.vue'; import AddressBar from './index/AddressBar.vue';
import MailBox from '../components/MailBox.vue'; import MailBox from '../components/MailBox.vue';
@@ -15,12 +17,12 @@ import Appearance from './common/Appearance.vue';
import Webhook from './index/Webhook.vue'; import Webhook from './index/Webhook.vue';
import Attachment from './index/Attachment.vue'; import Attachment from './index/Attachment.vue';
import About from './common/About.vue'; import About from './common/About.vue';
import SimpleIndex from './index/SimpleIndex.vue'; import SimpleIndex from './index/SimpleIndex.vue';
const { loading, settings, openSettings, indexTab, globalTabplacement, useSimpleIndex } = useGlobalState() const { loading, settings, openSettings, indexTab, globalTabplacement, useSimpleIndex } = useGlobalState()
const message = useMessage() const message = useMessage()
const route = useRoute() const route = useRoute()
const isMobile = useIsMobile()
const SendMail = defineAsyncComponent(() => { const SendMail = defineAsyncComponent(() => {
loading.value = true; loading.value = true;
@@ -42,6 +44,7 @@ const { t } = useI18n({
saveToS3Success: 'save to s3 success', saveToS3Success: 'save to s3 success',
webhookSettings: 'Webhook Settings', webhookSettings: 'Webhook Settings',
query: 'Query', query: 'Query',
enterSimpleMode: 'Simple Mode',
}, },
zh: { zh: {
mailbox: '收件箱', mailbox: '收件箱',
@@ -55,6 +58,7 @@ const { t } = useI18n({
saveToS3Success: '保存到s3成功', saveToS3Success: '保存到s3成功',
webhookSettings: 'Webhook 设置', webhookSettings: 'Webhook 设置',
query: '查询', query: '查询',
enterSimpleMode: '极简模式',
} }
} }
}); });
@@ -133,6 +137,16 @@ onMounted(() => {
<div v-else> <div v-else>
<AddressBar /> <AddressBar />
<n-tabs v-if="settings.address" type="card" v-model:value="indexTab" :placement="globalTabplacement"> <n-tabs v-if="settings.address" type="card" v-model:value="indexTab" :placement="globalTabplacement">
<template #prefix v-if="!isMobile">
<n-button @click="useSimpleIndex = true" tertiary size="small">
<template #icon>
<n-icon>
<FullscreenExitOutlined />
</n-icon>
</template>
{{ t('enterSimpleMode') }}
</n-button>
</template>
<n-tab-pane name="mailbox" :tab="t('mailbox')"> <n-tab-pane name="mailbox" :tab="t('mailbox')">
<div v-if="showMailIdQuery" style="margin-bottom: 10px;"> <div v-if="showMailIdQuery" style="margin-bottom: 10px;">
<n-input-group> <n-input-group>
+86 -2
View File
@@ -33,7 +33,12 @@ const { t } = useI18n({
itemCount: 'itemCount', itemCount: 'itemCount',
query: 'Query', query: 'Query',
addressQueryTip: 'Leave blank to query all addresses', addressQueryTip: 'Leave blank to query all addresses',
actions: 'Actions' clearInbox: 'Clear Inbox',
clearSentItems: 'Clear Sent Items',
clearInboxTip: 'Are you sure to clear inbox for this email?',
clearSentItemsTip: 'Are you sure to clear sent items for this email?',
actions: 'Actions',
success: 'Success',
}, },
zh: { zh: {
name: '名称', name: '名称',
@@ -52,7 +57,12 @@ const { t } = useI18n({
itemCount: '总数', itemCount: '总数',
query: '查询', query: '查询',
addressQueryTip: '留空查询所有地址', addressQueryTip: '留空查询所有地址',
clearInbox: '清空收件箱',
clearSentItems: '清空发件箱',
clearInboxTip: '确定要清空这个邮箱的收件箱吗?',
clearSentItemsTip: '确定要清空这个邮箱的发件箱吗?',
actions: '操作', actions: '操作',
success: '成功',
} }
} }
}); });
@@ -60,6 +70,8 @@ const { t } = useI18n({
const showEmailCredential = ref(false) const showEmailCredential = ref(false)
const curEmailCredential = ref("") const curEmailCredential = ref("")
const curDeleteAddressId = ref(0); const curDeleteAddressId = ref(0);
const curClearInboxAddressId = ref(0);
const curClearSentItemsAddressId = ref(0);
const addressQuery = ref("") const addressQuery = ref("")
@@ -68,6 +80,8 @@ const count = ref(0)
const page = ref(1) const page = ref(1)
const pageSize = ref(20) const pageSize = ref(20)
const showDeleteAccount = ref(false) const showDeleteAccount = ref(false)
const showClearInbox = ref(false)
const showClearSentItems = ref(false)
const showCredential = async (id) => { const showCredential = async (id) => {
try { try {
@@ -83,7 +97,7 @@ const showCredential = async (id) => {
const deleteEmail = async () => { const deleteEmail = async () => {
try { try {
await api.adminDeleteAddress(curDeleteAddressId.value) await api.adminDeleteAddress(curDeleteAddressId.value)
message.success("success"); message.success(t("success"));
await fetchData() await fetchData()
} catch (error) { } catch (error) {
message.error(error.message || "error"); message.error(error.message || "error");
@@ -92,6 +106,34 @@ const deleteEmail = async () => {
} }
} }
const clearInbox = async () => {
try {
await api.fetch(`/admin/clear_inbox/${curClearInboxAddressId.value}`, {
method: 'DELETE'
});
message.success(t("success"));
await fetchData()
} catch (error) {
message.error(error.message || "error");
} finally {
showClearInbox.value = false
}
}
const clearSentItems = async () => {
try {
await api.fetch(`/admin/clear_sent_items/${curClearSentItemsAddressId.value}`, {
method: 'DELETE'
});
message.success(t("success"));
await fetchData()
} catch (error) {
message.error(error.message || "error");
} finally {
showClearSentItems.value = false
}
}
const fetchData = async () => { const fetchData = async () => {
try { try {
addressQuery.value = addressQuery.value.trim() addressQuery.value = addressQuery.value.trim()
@@ -228,6 +270,32 @@ const columns = [
), ),
show: row.send_count > 0 show: row.send_count > 0
}, },
{
label: () => h(NButton,
{
text: true,
onClick: () => {
curClearInboxAddressId.value = row.id;
showClearInbox.value = true;
}
},
{ default: () => t('clearInbox') }
),
show: row.mail_count > 0
},
{
label: () => h(NButton,
{
text: true,
onClick: () => {
curClearSentItemsAddressId.value = row.id;
showClearSentItems.value = true;
}
},
{ default: () => t('clearSentItems') }
),
show: row.send_count > 0
},
{ {
label: () => h(NButton, label: () => h(NButton,
{ {
@@ -281,6 +349,22 @@ onMounted(async () => {
</n-button> </n-button>
</template> </template>
</n-modal> </n-modal>
<n-modal v-model:show="showClearInbox" preset="dialog" :title="t('clearInbox')">
<p>{{ t('clearInboxTip') }}</p>
<template #action>
<n-button :loading="loading" @click="clearInbox" size="small" tertiary type="error">
{{ t('clearInbox') }}
</n-button>
</template>
</n-modal>
<n-modal v-model:show="showClearSentItems" preset="dialog" :title="t('clearSentItems')">
<p>{{ t('clearSentItemsTip') }}</p>
<template #action>
<n-button :loading="loading" @click="clearSentItems" size="small" tertiary type="error">
{{ t('clearSentItems') }}
</n-button>
</template>
</n-modal>
<n-input-group> <n-input-group>
<n-input v-model:value="addressQuery" clearable :placeholder="t('addressQueryTip')" <n-input v-model:value="addressQuery" clearable :placeholder="t('addressQueryTip')"
@keydown.enter="fetchData" /> @keydown.enter="fetchData" />
+38 -6
View File
@@ -13,6 +13,7 @@ const { t } = useI18n({
messages: { messages: {
en: { en: {
tip: 'You can manually input the following multiple select input and enter', tip: 'You can manually input the following multiple select input and enter',
manualInputPrompt: 'Type and press Enter to add',
save: 'Save', save: 'Save',
successTip: 'Save Success', successTip: 'Save Success',
address_block_list: 'Address Block Keywords for Users(Admin can skip)', address_block_list: 'Address Block Keywords for Users(Admin can skip)',
@@ -38,6 +39,7 @@ const { t } = useI18n({
}, },
zh: { zh: {
tip: '您可以手动输入以下多选输入框, 回车增加', tip: '您可以手动输入以下多选输入框, 回车增加',
manualInputPrompt: '输入后按回车键添加',
save: '保存', save: '保存',
successTip: '保存成功', successTip: '保存成功',
address_block_list: '邮件地址屏蔽关键词(管理员可跳过检查)', address_block_list: '邮件地址屏蔽关键词(管理员可跳过检查)',
@@ -209,25 +211,55 @@ onMounted(async () => {
</n-flex> </n-flex>
<n-form-item-row :label="t('address_block_list')"> <n-form-item-row :label="t('address_block_list')">
<n-select v-model:value="addressBlockList" filterable multiple tag <n-select v-model:value="addressBlockList" filterable multiple tag
:placeholder="t('address_block_list_placeholder')" /> :placeholder="t('address_block_list_placeholder')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('send_address_block_list')"> <n-form-item-row :label="t('send_address_block_list')">
<n-select v-model:value="sendAddressBlockList" filterable multiple tag <n-select v-model:value="sendAddressBlockList" filterable multiple tag
:placeholder="t('address_block_list_placeholder')" /> :placeholder="t('address_block_list_placeholder')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('noLimitSendAddressList')"> <n-form-item-row :label="t('noLimitSendAddressList')">
<n-select v-model:value="noLimitSendAddressList" filterable multiple tag <n-select v-model:value="noLimitSendAddressList" filterable multiple tag
:placeholder="t('noLimitSendAddressList')" /> :placeholder="t('noLimitSendAddressList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('verified_address_list')"> <n-form-item-row :label="t('verified_address_list')">
<n-select v-model:value="verifiedAddressList" filterable multiple tag <n-select v-model:value="verifiedAddressList" filterable multiple tag
:placeholder="t('verified_address_list')" /> :placeholder="t('verified_address_list')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('fromBlockList')"> <n-form-item-row :label="t('fromBlockList')">
<n-select v-model:value="fromBlockList" filterable multiple tag :placeholder="t('fromBlockList')" /> <n-select v-model:value="fromBlockList" filterable multiple tag :placeholder="t('fromBlockList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('block_receive_unknow_address_email')"> <n-form-item-row :label="t('block_receive_unknow_address_email')">
<n-checkbox v-model:checked="emailRuleSettings.blockReceiveUnknowAddressEmail" /> <n-switch v-model:value="emailRuleSettings.blockReceiveUnknowAddressEmail" :round="false" />
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('email_forwarding_config')"> <n-form-item-row :label="t('email_forwarding_config')">
<n-button @click="openEmailForwardingModal">{{ t('config') }}</n-button> <n-button @click="openEmailForwardingModal">{{ t('config') }}</n-button>
+1 -1
View File
@@ -77,7 +77,7 @@ onMounted(async () => {
</n-modal> </n-modal>
<n-card :bordered="false" embedded style="max-width: 600px;"> <n-card :bordered="false" embedded style="max-width: 600px;">
<n-form-item-row v-if="openSettings.prefix" :label="t('enablePrefix')"> <n-form-item-row v-if="openSettings.prefix" :label="t('enablePrefix')">
<n-checkbox v-model:checked="enablePrefix" /> <n-switch v-model:value="enablePrefix" :round="false" />
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('address')"> <n-form-item-row :label="t('address')">
<n-input-group> <n-input-group>
+44 -23
View File
@@ -15,25 +15,29 @@ const { t } = useI18n({
init: 'Init', init: 'Init',
successTip: 'Success', successTip: 'Success',
status: 'Check Status', status: 'Check Status',
enableTelegramAllowList: 'Enable Telegram Allow List(Manually input user ID)', enableTelegramAllowList: 'Enable Telegram Allow List(Manually input Chat ID)',
enable: 'Enable', enable: 'Enable',
telegramAllowList: 'Telegram Allow List(Manually input telegram user ID)', telegramAllowList: 'Telegram Allow List(Manually input telegram Chat ID)',
manualInputPrompt: 'Type and press Enter to add',
save: 'Save', save: 'Save',
miniAppUrl: 'Telegram Mini App URL', miniAppUrl: 'Telegram Mini App URL',
enableGlobalMailPush: 'Enable Global Mail Push(Manually input telegram user ID)', enableGlobalMailPush: 'Enable Global Mail Push(Manually input telegram Chat ID)',
globalMailPushList: 'Global Mail Push List', globalMailPushList: 'Global Mail Push Chat ID List',
globalMailPushListTip: 'Support chat_id of private chat/group/channel. You can send a message to your bot, then visit this link to see chat_id, https://api.telegram.org/bot<Replace with your BOT TOKEN>/getUpdates',
}, },
zh: { zh: {
init: '初始化', init: '初始化',
successTip: '成功', successTip: '成功',
status: '查看状态', status: '查看状态',
enableTelegramAllowList: '启用 Telegram 白名单(手动输入用户 ID, 回车增加)', enableTelegramAllowList: '启用 Telegram 白名单(手动输入 Chat ID, 回车增加)',
enable: '启用', enable: '启用',
telegramAllowList: 'Telegram 白名单(手动输入用户 ID, 回车增加)', telegramAllowList: 'Telegram 白名单(手动输入 Chat ID, 回车增加)',
manualInputPrompt: '输入后按回车键添加',
save: '保存', save: '保存',
miniAppUrl: '电报小程序 URL(请输入你部署的电报小程序网页地址)', miniAppUrl: '电报小程序 URL(请输入你部署的电报小程序网页地址)',
enableGlobalMailPush: '启用全局邮件推送(手动输入邮箱管理员的 telegram 用户 ID, 回车增加)', enableGlobalMailPush: '启用全局邮件推送(手动输入邮箱管理员的 telegram Chat ID, 回车增加)',
globalMailPushList: '全局邮件推送用户列表', globalMailPushList: '全局邮件推送 Chat ID 列表',
globalMailPushListTip: '支持对话/群组/频道的 Chat ID, 您可以发送一条消息给您的机器人,然后访问此链接来查看 chat_id, https://api.telegram.org/bot<这里替换成您的 BOT TOKEN>/getUpdates',
} }
} }
}); });
@@ -113,6 +117,17 @@ onMounted(async () => {
<template> <template>
<div class="center"> <div class="center">
<n-card :bordered="false" embedded style="max-width: 800px; overflow: auto;"> <n-card :bordered="false" embedded style="max-width: 800px; overflow: auto;">
<n-flex justify="end">
<n-button @click="fetchStatus" secondary>
{{ t('status') }}
</n-button>
<n-button @click="init" type="primary">
{{ t('init') }}
</n-button>
<n-button @click="saveSettings" type="primary">
{{ t('save') }}
</n-button>
</n-flex>
<n-card :bordered="false" embedded> <n-card :bordered="false" embedded>
<n-form-item-row :label="t('enableTelegramAllowList')"> <n-form-item-row :label="t('enableTelegramAllowList')">
<n-input-group> <n-input-group>
@@ -120,31 +135,41 @@ onMounted(async () => {
{{ t('enable') }} {{ t('enable') }}
</n-checkbox> </n-checkbox>
<n-select v-model:value="settings.allowList" filterable multiple tag style="width: 80%;" <n-select v-model:value="settings.allowList" filterable multiple tag style="width: 80%;"
:placeholder="t('telegramAllowList')" /> :placeholder="t('telegramAllowList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-input-group> </n-input-group>
</n-form-item-row> </n-form-item-row>
<br />
<n-form-item-row :label="t('enableGlobalMailPush')"> <n-form-item-row :label="t('enableGlobalMailPush')">
<n-input-group> <n-input-group>
<n-checkbox v-model:checked="settings.enableGlobalMailPush" style="width: 20%;"> <n-checkbox v-model:checked="settings.enableGlobalMailPush" style="width: 20%;">
{{ t('enable') }} {{ t('enable') }}
</n-checkbox> </n-checkbox>
<n-select v-model:value="settings.globalMailPushList" filterable multiple tag <n-select v-model:value="settings.globalMailPushList" filterable multiple tag
style="width: 80%;" :placeholder="t('globalMailPushList')" /> style="width: 80%;" :placeholder="t('globalMailPushList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-input-group> </n-input-group>
<template #feedback>
<n-text depth="3">
{{ t('globalMailPushListTip') }}
</n-text>
</template>
</n-form-item-row> </n-form-item-row>
<br />
<n-form-item-row :label="t('miniAppUrl')"> <n-form-item-row :label="t('miniAppUrl')">
<n-input v-model:value="settings.miniAppUrl"></n-input> <n-input v-model:value="settings.miniAppUrl"></n-input>
</n-form-item-row> </n-form-item-row>
<n-button @click="saveSettings" type="primary" block>
{{ t('save') }}
</n-button>
</n-card> </n-card>
<n-button @click="init" type="primary" block>
{{ t('init') }}
</n-button>
<n-button @click="fetchStatus" secondary block>
{{ t('status') }}
</n-button>
<pre v-if="status.fetched">{{ JSON.stringify(status, null, 2) }}</pre> <pre v-if="status.fetched">{{ JSON.stringify(status, null, 2) }}</pre>
</n-card> </n-card>
</div> </div>
@@ -157,8 +182,4 @@ onMounted(async () => {
place-items: center; place-items: center;
justify-content: center; justify-content: center;
} }
.n-button {
margin-top: 10px;
}
</style> </style>
@@ -21,6 +21,7 @@ const { t } = useI18n({
successTip: 'Save Success', successTip: 'Save Success',
enable: 'Enable', enable: 'Enable',
enableMailAllowList: 'Enable Mail Address Allow List(Manually enterable)', enableMailAllowList: 'Enable Mail Address Allow List(Manually enterable)',
manualInputPrompt: 'Type and press Enter to add',
mailAllowList: 'Mail Address Allow List', mailAllowList: 'Mail Address Allow List',
addOauth2: 'Add Oauth2', addOauth2: 'Add Oauth2',
name: 'Name', name: 'Name',
@@ -33,6 +34,7 @@ const { t } = useI18n({
successTip: '保存成功', successTip: '保存成功',
enable: '启用', enable: '启用',
enableMailAllowList: '启用邮件地址白名单(可手动输入, 回车增加)', enableMailAllowList: '启用邮件地址白名单(可手动输入, 回车增加)',
manualInputPrompt: '输入后按回车键添加',
mailAllowList: '邮件地址白名单', mailAllowList: '邮件地址白名单',
addOauth2: '添加 Oauth2', addOauth2: '添加 Oauth2',
name: '名称', name: '名称',
@@ -184,7 +186,7 @@ onMounted(async () => {
</template> </template>
</n-modal> </n-modal>
<n-card :bordered="false" embedded style="max-width: 600px;"> <n-card :bordered="false" embedded style="max-width: 600px;">
<n-alert :show-icon="false" type="warning" closable style="margin-bottom: 10px;"> <n-alert :show-icon="false" :bordered="false" type="warning" closable style="margin-bottom: 10px;">
{{ t("tip") }} {{ t("tip") }}
</n-alert> </n-alert>
<n-flex justify="end"> <n-flex justify="end">
@@ -246,7 +248,13 @@ onMounted(async () => {
</n-checkbox> </n-checkbox>
<n-select v-model:value="item.mailAllowList" v-if="item.enableMailAllowList" filterable <n-select v-model:value="item.mailAllowList" v-if="item.enableMailAllowList" filterable
multiple tag style="width: 80%;" :options="mailAllowOptions" multiple tag style="width: 80%;" :options="mailAllowOptions"
:placeholder="t('mailAllowList')" /> :placeholder="t('mailAllowList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-input-group> </n-input-group>
</n-form-item-row> </n-form-item-row>
</n-form> </n-form>
+15 -5
View File
@@ -18,6 +18,7 @@ const { t } = useI18n({
enableMailVerify: 'Enable Mail Verify (Send address must be an address in the system with a balance and can send mail normally)', enableMailVerify: 'Enable Mail Verify (Send address must be an address in the system with a balance and can send mail normally)',
verifyMailSender: 'Verify Mail Sender', verifyMailSender: 'Verify Mail Sender',
enableMailAllowList: 'Enable Mail Address Allow List(Manually enterable)', enableMailAllowList: 'Enable Mail Address Allow List(Manually enterable)',
manualInputPrompt: 'Type and press Enter to add',
mailAllowList: 'Mail Address Allow List', mailAllowList: 'Mail Address Allow List',
maxAddressCount: 'Maximum number of email addresses that can be binded', maxAddressCount: 'Maximum number of email addresses that can be binded',
}, },
@@ -29,6 +30,7 @@ const { t } = useI18n({
enableMailVerify: '启用邮件验证(发送地址必须是系统中能有余额且能正常发送邮件的地址)', enableMailVerify: '启用邮件验证(发送地址必须是系统中能有余额且能正常发送邮件的地址)',
verifyMailSender: '验证邮件发送地址', verifyMailSender: '验证邮件发送地址',
enableMailAllowList: '启用邮件地址白名单(可手动输入, 回车增加)', enableMailAllowList: '启用邮件地址白名单(可手动输入, 回车增加)',
manualInputPrompt: '输入后按回车键添加',
mailAllowList: '邮件地址白名单', mailAllowList: '邮件地址白名单',
maxAddressCount: '可绑定最大邮箱地址数量', maxAddressCount: '可绑定最大邮箱地址数量',
} }
@@ -83,9 +85,14 @@ onMounted(async () => {
<template> <template>
<div class="center"> <div class="center">
<n-card :bordered="false" embedded style="max-width: 600px;"> <n-card :bordered="false" embedded style="max-width: 600px;">
<n-flex justify="end">
<n-button @click="save" type="primary" :loading="loading">
{{ t('save') }}
</n-button>
</n-flex>
<n-form :model="userSettings"> <n-form :model="userSettings">
<n-form-item-row :label="t('enableUserRegister')"> <n-form-item-row :label="t('enableUserRegister')">
<n-checkbox v-model:checked="userSettings.enable" /> <n-switch v-model:value="userSettings.enable" :round="false" />
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('enableMailVerify')"> <n-form-item-row :label="t('enableMailVerify')">
<n-input-group> <n-input-group>
@@ -103,7 +110,13 @@ onMounted(async () => {
</n-checkbox> </n-checkbox>
<n-select v-model:value="userSettings.mailAllowList" v-if="userSettings.enableMailAllowList" <n-select v-model:value="userSettings.mailAllowList" v-if="userSettings.enableMailAllowList"
filterable multiple tag style="width: 80%;" :options="mailAllowOptions" filterable multiple tag style="width: 80%;" :options="mailAllowOptions"
:placeholder="t('mailAllowList')" /> :placeholder="t('mailAllowList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-input-group> </n-input-group>
</n-form-item-row> </n-form-item-row>
<n-form-item-row :label="t('maxAddressCount')"> <n-form-item-row :label="t('maxAddressCount')">
@@ -112,9 +125,6 @@ onMounted(async () => {
:placeholder="t('maxAddressCount')" /> :placeholder="t('maxAddressCount')" />
</n-input-group> </n-input-group>
</n-form-item-row> </n-form-item-row>
<n-button @click="save" type="primary" block :loading="loading">
{{ t('save') }}
</n-button>
</n-form> </n-form>
</n-card> </n-card>
</div> </div>
+26 -9
View File
@@ -13,13 +13,17 @@ const { t } = useI18n({
messages: { messages: {
en: { en: {
successTip: 'Success', successTip: 'Success',
webhookAllowList: 'Webhook Allow List(Enter the address that is allowed to use webhook and enter)', enableAllowList: 'Enable Allow List (Restrict webhook access to specific users)',
webhookAllowList: 'Webhook Allow List(Enter the mail address that is allowed to use webhook and enter)',
manualInputPrompt: 'Type and press Enter to add',
save: 'Save', save: 'Save',
notEnabled: 'Webhook is not enabled', notEnabled: 'Webhook is not enabled',
}, },
zh: { zh: {
successTip: '成功', successTip: '成功',
webhookAllowList: 'Webhook 白名单(请输入允许使用webhook 的地址, 回车增加)', enableAllowList: '启用白名单 (限制 webhook 访问权限,只有白名单中的用户可以使用)',
webhookAllowList: 'Webhook 白名单(请输入允许使用webhook 的邮箱地址, 回车增加)',
manualInputPrompt: '输入后按回车键添加',
save: '保存', save: '保存',
notEnabled: 'Webhook 未开启', notEnabled: 'Webhook 未开启',
} }
@@ -27,14 +31,16 @@ const { t } = useI18n({
}); });
class WebhookSettings { class WebhookSettings {
enableAllowList: boolean;
allowList: string[]; allowList: string[];
constructor(allowList: string[]) { constructor(enableAllowList: boolean, allowList: string[]) {
this.enableAllowList = enableAllowList;
this.allowList = allowList; this.allowList = allowList;
} }
} }
const webhookSettings = ref(new WebhookSettings([])) const webhookSettings = ref(new WebhookSettings(false, []))
const webhookEnabled = ref(false) const webhookEnabled = ref(false)
const errorInfo = ref('') const errorInfo = ref('')
@@ -68,13 +74,24 @@ onMounted(async () => {
<template> <template>
<div class="center"> <div class="center">
<n-card v-if="webhookEnabled" :bordered="false" embedded style="max-width: 800px; overflow: auto;"> <n-card v-if="webhookEnabled" :bordered="false" embedded style="max-width: 800px; overflow: auto;">
<n-form-item-row :label="t('webhookAllowList')"> <n-flex justify="end">
<n-select v-model:value="webhookSettings.allowList" filterable multiple tag <n-button @click="saveSettings" type="primary">
:placeholder="t('webhookAllowList')" />
</n-form-item-row>
<n-button @click="saveSettings" type="primary" block>
{{ t('save') }} {{ t('save') }}
</n-button> </n-button>
</n-flex>
<n-form-item-row :label="t('enableAllowList')">
<n-switch v-model:value="webhookSettings.enableAllowList" :round="false" />
</n-form-item-row>
<n-form-item-row :label="t('webhookAllowList')">
<n-select v-model:value="webhookSettings.allowList" filterable multiple tag
:placeholder="t('webhookAllowList')">
<template #empty>
<n-text depth="3">
{{ t('manualInputPrompt') }}
</n-text>
</template>
</n-select>
</n-form-item-row>
</n-card> </n-card>
<n-result v-else status="404" :title="t('notEnabled')" :description="errorInfo" /> <n-result v-else status="404" :title="t('notEnabled')" :description="errorInfo" />
</div> </div>
+1 -1
View File
@@ -26,7 +26,7 @@ onMounted(async () => {
<template> <template>
<div class="center"> <div class="center">
<n-card :bordered="false" embedded style="max-width: 600px; overflow: auto;"> <n-card :bordered="false" embedded style="max-width: 800px; overflow: auto;">
<pre>{{ JSON.stringify(settings, null, 2) }}</pre> <pre>{{ JSON.stringify(settings, null, 2) }}</pre>
</n-card> </n-card>
</div> </div>
+10 -5
View File
@@ -84,6 +84,7 @@ const { locale, t } = useI18n({
credentialInput: 'Please input the Mail Address Credential', credentialInput: 'Please input the Mail Address Credential',
bindUserInfo: 'Logged in user, login without binding email or create new email address will bind to current user', bindUserInfo: 'Logged in user, login without binding email or create new email address will bind to current user',
bindUserAddressError: 'Error when bind email address to user', bindUserAddressError: 'Error when bind email address to user',
autoGeneratedName: 'Auto-generated name',
}, },
zh: { zh: {
login: '登录', login: '登录',
@@ -100,6 +101,7 @@ const { locale, t } = useI18n({
credentialInput: '请输入邮箱地址凭据', credentialInput: '请输入邮箱地址凭据',
bindUserInfo: '已登录用户, 登录未绑定邮箱或创建新邮箱地址将绑定到当前用户', bindUserInfo: '已登录用户, 登录未绑定邮箱或创建新邮箱地址将绑定到当前用户',
bindUserAddressError: '绑定邮箱地址到用户时错误', bindUserAddressError: '绑定邮箱地址到用户时错误',
autoGeneratedName: '自动生成名称',
} }
} }
}); });
@@ -147,8 +149,10 @@ const generateName = async () => {
const newEmail = async () => { const newEmail = async () => {
try { try {
// If custom names are disabled, send empty name to trigger backend auto-generation
const nameToSend = openSettings.value.disableCustomAddressName ? "" : emailName.value;
const res = await props.newAddressPath( const res = await props.newAddressPath(
emailName.value, nameToSend,
emailDomain.value, emailDomain.value,
cfToken.value cfToken.value
); );
@@ -240,19 +244,20 @@ onMounted(async () => {
<n-spin :show="generateNameLoading"> <n-spin :show="generateNameLoading">
<n-form> <n-form>
<span> <span>
<p>{{ t("getNewEmailTip1") + addressRegex.source }}</p> <p v-if="!openSettings.disableCustomAddressName">{{ t("getNewEmailTip1") + addressRegex.source }}</p>
<p>{{ t("getNewEmailTip2") }}</p> <p v-if="!openSettings.disableCustomAddressName">{{ t("getNewEmailTip2") }}</p>
<p>{{ t("getNewEmailTip3") }}</p> <p>{{ t("getNewEmailTip3") }}</p>
</span> </span>
<n-button @click="generateName" style="margin-bottom: 10px;"> <n-button v-if="!openSettings.disableCustomAddressName" @click="generateName" style="margin-bottom: 10px;">
{{ t('generateName') }} {{ t('generateName') }}
</n-button> </n-button>
<n-input-group> <n-input-group>
<n-input-group-label v-if="addressPrefix"> <n-input-group-label v-if="addressPrefix">
{{ addressPrefix }} {{ addressPrefix }}
</n-input-group-label> </n-input-group-label>
<n-input v-model:value="emailName" show-count :minlength="openSettings.minAddressLen" <n-input v-if="!openSettings.disableCustomAddressName" v-model:value="emailName" show-count :minlength="openSettings.minAddressLen"
:maxlength="openSettings.maxAddressLen" /> :maxlength="openSettings.maxAddressLen" />
<n-input v-else :value="t('autoGeneratedName')" disabled />
<n-input-group-label>@</n-input-group-label> <n-input-group-label>@</n-input-group-label>
<n-select v-model:value="emailDomain" :consistent-menu-width="false" <n-select v-model:value="emailDomain" :consistent-menu-width="false"
:options="domainsOptions" /> :options="domainsOptions" />
+65 -2
View File
@@ -8,13 +8,15 @@ import { api } from '../../api'
import { getRouterPathWithLang } from '../../utils' import { getRouterPathWithLang } from '../../utils'
const { const {
jwt, settings, showAddressCredential, loading jwt, settings, showAddressCredential, loading, openSettings
} = useGlobalState() } = useGlobalState()
const router = useRouter() const router = useRouter()
const message = useMessage() const message = useMessage()
const showLogout = ref(false) const showLogout = ref(false)
const showDeleteAccount = ref(false) const showDeleteAccount = ref(false)
const showClearInbox = ref(false)
const showClearSentItems = ref(false)
const { locale, t } = useI18n({ const { locale, t } = useI18n({
messages: { messages: {
en: { en: {
@@ -24,6 +26,11 @@ const { locale, t } = useI18n({
logoutConfirm: 'Are you sure to logout?', logoutConfirm: 'Are you sure to logout?',
deleteAccount: "Delete Account", deleteAccount: "Delete Account",
deleteAccountConfirm: "Are you sure to delete your account and all emails for this account?", deleteAccountConfirm: "Are you sure to delete your account and all emails for this account?",
clearInbox: "Clear Inbox",
clearSentItems: "Clear Sent Items",
clearInboxConfirm: "Are you sure to clear all emails in your inbox?",
clearSentItemsConfirm: "Are you sure to clear all emails in your sent items?",
success: "Success",
}, },
zh: { zh: {
logout: '退出登录', logout: '退出登录',
@@ -32,6 +39,11 @@ const { locale, t } = useI18n({
logoutConfirm: '确定要退出登录吗?', logoutConfirm: '确定要退出登录吗?',
deleteAccount: "删除账户", deleteAccount: "删除账户",
deleteAccountConfirm: "确定要删除你的账户和其中的所有邮件吗?", deleteAccountConfirm: "确定要删除你的账户和其中的所有邮件吗?",
clearInbox: "清空收件箱",
clearSentItems: "清空发件箱",
clearInboxConfirm: "确定要清空你收件箱中的所有邮件吗?",
clearSentItemsConfirm: "确定要清空你发件箱中的所有邮件吗?",
success: "成功",
} }
} }
}); });
@@ -54,6 +66,32 @@ const deleteAccount = async () => {
message.error(error.message || "error"); message.error(error.message || "error");
} }
}; };
const clearInbox = async () => {
try {
await api.fetch(`/api/clear_inbox`, {
method: 'DELETE'
});
message.success(t("success"));
} catch (error) {
message.error(error.message || "error");
} finally {
showClearInbox.value = false;
}
};
const clearSentItems = async () => {
try {
await api.fetch(`/api/clear_sent_items`, {
method: 'DELETE'
});
message.success(t("success"));
} catch (error) {
message.error(error.message || "error");
} finally {
showClearSentItems.value = false;
}
};
</script> </script>
<template> <template>
@@ -62,10 +100,19 @@ const deleteAccount = async () => {
<n-button @click="showAddressCredential = true" type="primary" secondary block strong> <n-button @click="showAddressCredential = true" type="primary" secondary block strong>
{{ t('showAddressCredential') }} {{ t('showAddressCredential') }}
</n-button> </n-button>
<n-button v-if="openSettings.enableUserDeleteEmail" @click="showClearInbox = true" type="warning" secondary
block strong>
{{ t('clearInbox') }}
</n-button>
<n-button v-if="openSettings.enableUserDeleteEmail" @click="showClearSentItems = true" type="warning"
secondary block strong>
{{ t('clearSentItems') }}
</n-button>
<n-button @click="showLogout = true" secondary block strong> <n-button @click="showLogout = true" secondary block strong>
{{ t('logout') }} {{ t('logout') }}
</n-button> </n-button>
<n-button @click="showDeleteAccount = true" type="error" secondary block strong> <n-button v-if="openSettings.enableUserDeleteEmail" @click="showDeleteAccount = true" type="error" secondary
block strong>
{{ t('deleteAccount') }} {{ t('deleteAccount') }}
</n-button> </n-button>
</n-card> </n-card>
@@ -85,6 +132,22 @@ const deleteAccount = async () => {
</n-button> </n-button>
</template> </template>
</n-modal> </n-modal>
<n-modal v-model:show="showClearInbox" preset="dialog" :title="t('clearInbox')">
<p>{{ t('clearInboxConfirm') }}</p>
<template #action>
<n-button :loading="loading" @click="clearInbox" size="small" tertiary type="warning">
{{ t('clearInbox') }}
</n-button>
</template>
</n-modal>
<n-modal v-model:show="showClearSentItems" preset="dialog" :title="t('clearSentItems')">
<p>{{ t('clearSentItemsConfirm') }}</p>
<template #action>
<n-button :loading="loading" @click="clearSentItems" size="small" tertiary type="warning">
{{ t('clearSentItems') }}
</n-button>
</template>
</n-modal>
</div> </div>
</template> </template>
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "temp-email-pages", "name": "temp-email-pages",
"version": "1.0.4", "version": "1.0.5",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
@@ -11,7 +11,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"wrangler": "^4.32.0" "wrangler": "^4.34.0"
}, },
"packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39" "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39"
} }
@@ -24,9 +24,9 @@ res = requests.post(
print(res.json()) print(res.json())
``` ```
# 批量创建随机用户名邮箱地址 API 示例 ## 批量创建随机用户名邮箱地址 API 示例
## 通过 admin API 批量新建邮箱地址 ### 通过 admin API 批量新建邮箱地址
这是一个 `python` 的例子,使用 `requests` 库发送邮件。 这是一个 `python` 的例子,使用 `requests` 库发送邮件。
+3 -1
View File
@@ -23,13 +23,15 @@
## 邮箱相关变量 ## 邮箱相关变量
| 变量名 | 类型 | 说明 | 示例 | | 变量名 | 类型 | 说明 | 示例 |
| ---------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | | ------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
| `PREFIX` | 文本 | 新建 `邮箱名称` 的默认前缀,不需要前缀可不配置 | `tmp` | | `PREFIX` | 文本 | 新建 `邮箱名称` 的默认前缀,不需要前缀可不配置 | `tmp` |
| `MIN_ADDRESS_LEN` | 数字 | `邮箱名称` 的最小长度 | `1` | | `MIN_ADDRESS_LEN` | 数字 | `邮箱名称` 的最小长度 | `1` |
| `MAX_ADDRESS_LEN` | 数字 | `邮箱名称` 的最大长度 | `30` | | `MAX_ADDRESS_LEN` | 数字 | `邮箱名称` 的最大长度 | `30` |
| `DISABLE_CUSTOM_ADDRESS_NAME` | 文本/JSON | 禁用自定义邮箱地址名称,如果设置为 true,则用户无法输入自定义邮箱名称,将由后台自动生成 | `true` |
| `ADDRESS_CHECK_REGEX` | 文本 | `邮箱名称` 的正则表达式, 只用于检查 | `^(?!.*admin).*` | | `ADDRESS_CHECK_REGEX` | 文本 | `邮箱名称` 的正则表达式, 只用于检查 | `^(?!.*admin).*` |
| `ADDRESS_REGEX` | 文本 | `邮箱名称` 替换非法符号的正则表达式, 不在其中的符号将被替换,如果不设置,默认为 `[^a-z0-9]`, 需谨慎使用, 有些符号可能导致无法收件 | `[^a-z0-9]` | | `ADDRESS_REGEX` | 文本 | `邮箱名称` 替换非法符号的正则表达式, 不在其中的符号将被替换,如果不设置,默认为 `[^a-z0-9]`, 需谨慎使用, 有些符号可能导致无法收件 | `[^a-z0-9]` |
| `DEFAULT_DOMAINS` | JSON | 默认用户可用的域名(未登录或未分配角色的用户) | `["awsl.uk", "dreamhunter2333.xyz"]` | | `DEFAULT_DOMAINS` | JSON | 默认用户可用的域名(未登录或未分配角色的用户) | `["awsl.uk", "dreamhunter2333.xyz"]` |
| `CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST` | 文本/JSON | 创建新地址时是否优先使用默认域名,如果设置为 true,当未指定域名时将使用第一个域名, 主要用于 telegram bot 场景 | `false` |
| `DOMAIN_LABELS` | JSON | 对于中文域名,可以使用 DOMAIN_LABELS 显示域名的中文展示名称 | `["中文.awsl.uk", "dreamhunter2333.xyz"]` | | `DOMAIN_LABELS` | JSON | 对于中文域名,可以使用 DOMAIN_LABELS 显示域名的中文展示名称 | `["中文.awsl.uk", "dreamhunter2333.xyz"]` |
| `ENABLE_AUTO_REPLY` | 文本/JSON | 允许自动回复邮件 | `true` | | `ENABLE_AUTO_REPLY` | 文本/JSON | 允许自动回复邮件 | `true` |
| `DEFAULT_SEND_BALANCE` | 文本/JSON | 默认发送邮件余额,如果不设置,将为 0 | `1` | | `DEFAULT_SEND_BALANCE` | 文本/JSON | 默认发送邮件余额,如果不设置,将为 0 | `1` |
+3 -3
View File
@@ -1,12 +1,12 @@
{ {
"name": "temp-mail-docs", "name": "temp-mail-docs",
"private": true, "private": true,
"version": "1.0.4", "version": "1.0.5",
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@types/node": "^24.3.0", "@types/node": "^24.3.1",
"vitepress": "^1.6.4", "vitepress": "^1.6.4",
"wrangler": "^4.32.0" "wrangler": "^4.34.0"
}, },
"scripts": { "scripts": {
"dev": "vitepress dev docs", "dev": "vitepress dev docs",
+346 -337
View File
File diff suppressed because it is too large Load Diff
+8 -8
View File
@@ -1,6 +1,6 @@
{ {
"name": "cloudflare_temp_email", "name": "cloudflare_temp_email",
"version": "1.0.4", "version": "1.0.5",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
@@ -11,20 +11,20 @@
"build": "wrangler deploy --dry-run --outdir dist --minify" "build": "wrangler deploy --dry-run --outdir dist --minify"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/workers-types": "^4.20250822.0", "@cloudflare/workers-types": "^4.20250904.0",
"@eslint/js": "9.18.0", "@eslint/js": "9.18.0",
"@simplewebauthn/types": "10.0.0", "@simplewebauthn/types": "10.0.0",
"@types/node": "^22.17.2", "@types/node": "^22.18.1",
"eslint": "9.18.0", "eslint": "9.18.0",
"globals": "^15.15.0", "globals": "^15.15.0",
"typescript-eslint": "^8.40.0", "typescript-eslint": "^8.42.0",
"wrangler": "^4.32.0" "wrangler": "^4.34.0"
}, },
"dependencies": { "dependencies": {
"@aws-sdk/client-s3": "^3.873.0", "@aws-sdk/client-s3": "^3.879.0",
"@aws-sdk/s3-request-presigner": "^3.873.0", "@aws-sdk/s3-request-presigner": "^3.879.0",
"@simplewebauthn/server": "10.0.1", "@simplewebauthn/server": "10.0.1",
"hono": "^4.9.4", "hono": "^4.9.6",
"jsonpath-plus": "^10.3.0", "jsonpath-plus": "^10.3.0",
"mimetext": "^3.0.27", "mimetext": "^3.0.27",
"postal-mime": "^2.4.4", "postal-mime": "^2.4.4",
+707 -712
View File
File diff suppressed because it is too large Load Diff
+28
View File
@@ -89,6 +89,34 @@ api.delete('/admin/delete_address/:id', async (c) => {
}) })
}) })
api.delete('/admin/clear_inbox/:id', async (c) => {
const { id } = c.req.param();
const { success: mailSuccess } = await c.env.DB.prepare(
`DELETE FROM raw_mails WHERE address IN`
+ ` (select name from address where id = ?) `
).bind(id).run();
if (!mailSuccess) {
return c.text("Failed to clear inbox", 500)
}
return c.json({
success: mailSuccess
})
})
api.delete('/admin/clear_sent_items/:id', async (c) => {
const { id } = c.req.param();
const { success: sendboxSuccess } = await c.env.DB.prepare(
`DELETE FROM sendbox WHERE address IN`
+ ` (select name from address where id = ?) `
).bind(id).run();
if (!sendboxSuccess) {
return c.text("Failed to clear sent items", 500)
}
return c.json({
success: sendboxSuccess
})
})
api.get('/admin/show_password/:id', async (c) => { api.get('/admin/show_password/:id', async (c) => {
const { id } = c.req.param(); const { id } = c.req.param();
const name = await c.env.DB.prepare( const name = await c.env.DB.prepare(
+1 -1
View File
@@ -4,7 +4,7 @@ import { AdminWebhookSettings } from "../models";
async function getWebhookSettings(c: Context<HonoCustomType>): Promise<Response> { async function getWebhookSettings(c: Context<HonoCustomType>): Promise<Response> {
const settings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json"); const settings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json");
return c.json(settings || new AdminWebhookSettings([])); return c.json(settings || new AdminWebhookSettings(false, []));
} }
async function saveWebhookSettings(c: Context<HonoCustomType>): Promise<Response> { async function saveWebhookSettings(c: Context<HonoCustomType>): Promise<Response> {
+2
View File
@@ -14,6 +14,7 @@ api.get('/open_api/settings', async (c) => {
const auth = c.req.raw.headers.get("x-custom-auth"); const auth = c.req.raw.headers.get("x-custom-auth");
needAuth = !auth || !passwords.includes(auth); needAuth = !auth || !passwords.includes(auth);
} }
return c.json({ return c.json({
"title": c.env.TITLE, "title": c.env.TITLE,
"announcement": utils.getStringValue(c.env.ANNOUNCEMENT), "announcement": utils.getStringValue(c.env.ANNOUNCEMENT),
@@ -29,6 +30,7 @@ api.get('/open_api/settings', async (c) => {
"adminContact": c.env.ADMIN_CONTACT, "adminContact": c.env.ADMIN_CONTACT,
"enableUserCreateEmail": utils.getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL), "enableUserCreateEmail": utils.getBooleanValue(c.env.ENABLE_USER_CREATE_EMAIL),
"disableAnonymousUserCreateEmail": utils.getBooleanValue(c.env.DISABLE_ANONYMOUS_USER_CREATE_EMAIL), "disableAnonymousUserCreateEmail": utils.getBooleanValue(c.env.DISABLE_ANONYMOUS_USER_CREATE_EMAIL),
"disableCustomAddressName": utils.getBooleanValue(c.env.DISABLE_CUSTOM_ADDRESS_NAME),
"enableUserDeleteEmail": utils.getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL), "enableUserDeleteEmail": utils.getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL),
"enableAutoReply": utils.getBooleanValue(c.env.ENABLE_AUTO_REPLY), "enableAutoReply": utils.getBooleanValue(c.env.ENABLE_AUTO_REPLY),
"enableIndexAbout": utils.getBooleanValue(c.env.ENABLE_INDEX_ABOUT), "enableIndexAbout": utils.getBooleanValue(c.env.ENABLE_INDEX_ABOUT),
+37 -9
View File
@@ -8,6 +8,31 @@ import { AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g; const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
export const generateRandomName = (c: Context<HonoCustomType>): string => {
// name min length min 1
const minLength = Math.max(
getIntValue(c.env.MIN_ADDRESS_LEN, 1),
1
);
// name max length min 1
const maxLength = Math.max(
getIntValue(c.env.MAX_ADDRESS_LEN, 30),
1
);
// Build full name recursively until minimum length is reached
const buildName = (currentName: string = ""): string => {
return currentName.length >= minLength
? currentName
: buildName(currentName + Math.random().toString(36).substring(2, 15));
};
const fullName = buildName();
// Return truncated to max length
return fullName.substring(0, Math.min(fullName.length, maxLength));
};
const checkNameRegex = (c: Context<HonoCustomType>, name: string) => { const checkNameRegex = (c: Context<HonoCustomType>, name: string) => {
let error = null; let error = null;
try { try {
@@ -76,8 +101,8 @@ export const newAddress = async (
enableCheckNameRegex?: boolean, enableCheckNameRegex?: boolean,
} }
): Promise<{ address: string, jwt: string }> => { ): Promise<{ address: string, jwt: string }> => {
// remove special characters // trim whitespace and remove special characters
name = name.replace(getNameRegex(c), '') name = name.trim().replace(getNameRegex(c), '')
// check name // check name
if (enableCheckNameRegex) { if (enableCheckNameRegex) {
await checkNameBlockList(c, name); await checkNameBlockList(c, name);
@@ -102,16 +127,21 @@ export const newAddress = async (
} }
// create address with prefix // create address with prefix
if (typeof addressPrefix === "string") { if (typeof addressPrefix === "string") {
name = addressPrefix + name; name = addressPrefix.trim() + name;
} else if (enablePrefix) { } else if (enablePrefix) {
name = getStringValue(c.env.PREFIX) + name; name = getStringValue(c.env.PREFIX).trim() + name;
} }
// check domain // check domain
const allowDomains = checkAllowDomains ? await getAllowDomains(c) : getDomains(c); const allowDomains = checkAllowDomains ? await getAllowDomains(c) : getDomains(c);
// if domain is not set, use the random domain // if domain is not set, select domain based on environment configuration
if (!domain && allowDomains.length > 0) { if (!domain && allowDomains.length > 0) {
const createAddressDefaultDomainFirst = getBooleanValue(c.env.CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST);
if (createAddressDefaultDomainFirst) {
domain = allowDomains[0];
} else {
domain = allowDomains[Math.floor(Math.random() * allowDomains.length)]; domain = allowDomains[Math.floor(Math.random() * allowDomains.length)];
} }
}
// check domain is valid // check domain is valid
if (!domain || !allowDomains.includes(domain)) { if (!domain || !allowDomains.includes(domain)) {
throw new Error("Invalid domain") throw new Error("Invalid domain")
@@ -238,9 +268,7 @@ const batchDeleteAddressWithData = async (
return true; return true;
} }
/**
* TODO: need senbox delete?
*/
export const deleteAddressWithData = async ( export const deleteAddressWithData = async (
c: Context<HonoCustomType>, c: Context<HonoCustomType>,
address: string | undefined | null, address: string | undefined | null,
@@ -450,7 +478,7 @@ export async function triggerWebhook(
// user mail webhook // user mail webhook
const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json"); const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json");
if (adminSettings?.allowList.includes(address)) { if (!adminSettings?.enableAllowList || adminSettings?.allowList.includes(address)) {
const settings = await c.env.KV.get<WebhookSettings>( const settings = await c.env.KV.get<WebhookSettings>(
`${CONSTANTS.WEBHOOK_KV_USER_SETTINGS_KEY}:${address}`, "json" `${CONSTANTS.WEBHOOK_KV_USER_SETTINGS_KEY}:${address}`, "json"
); );
+1 -1
View File
@@ -1,5 +1,5 @@
export const CONSTANTS = { export const CONSTANTS = {
VERSION: 'v' + '1.0.4', VERSION: 'v' + '1.0.5',
// DB Version // DB Version
DB_VERSION_KEY: 'db_version', DB_VERSION_KEY: 'db_version',
+44 -4
View File
@@ -2,7 +2,7 @@ import { Context, Hono } from 'hono'
import i18n from '../i18n'; import i18n from '../i18n';
import { getBooleanValue, getJsonSetting, checkCfTurnstile, getStringValue, getSplitStringListValue } from '../utils'; import { getBooleanValue, getJsonSetting, checkCfTurnstile, getStringValue, getSplitStringListValue } from '../utils';
import { newAddress, handleListQuery, deleteAddressWithData, getAddressPrefix, getAllowDomains, updateAddressUpdatedAt } from '../common' import { newAddress, handleListQuery, deleteAddressWithData, getAddressPrefix, getAllowDomains, updateAddressUpdatedAt, generateRandomName } from '../common'
import { CONSTANTS } from '../constants' import { CONSTANTS } from '../constants'
import auto_reply from './auto_reply' import auto_reply from './auto_reply'
import webhook_settings from './webhook_settings'; import webhook_settings from './webhook_settings';
@@ -123,9 +123,13 @@ api.post('/api/new_address', async (c) => {
} catch (error) { } catch (error) {
return c.text(msgs.TurnstileCheckFailedMsg, 500) return c.text(msgs.TurnstileCheckFailedMsg, 500)
} }
// if no name, generate random name // Check if custom email names are disabled from environment variable
if (!name) { const disableCustomAddressName = getBooleanValue(c.env.DISABLE_CUSTOM_ADDRESS_NAME);
name = Math.random().toString(36).substring(2, 15);
// if no name or custom names are disabled, generate random name
if (!name || disableCustomAddressName) {
// Generate random name with context-based length configuration
name = generateRandomName(c);
} }
// check name block list // check name block list
try { try {
@@ -158,3 +162,39 @@ api.delete('/api/delete_address', async (c) => {
success: success success: success
}) })
}) })
api.delete('/api/clear_inbox', async (c) => {
const lang = c.get("lang") || c.env.DEFAULT_LANG;
const msgs = i18n.getMessages(lang);
if (!getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL)) {
return c.text(msgs.UserDeleteEmailDisabledMsg, 403)
}
const { address } = c.get("jwtPayload")
const { success } = await c.env.DB.prepare(
`DELETE FROM raw_mails WHERE address = ?`
).bind(address).run();
if (!success) {
return c.text("Failed to clear inbox", 500)
}
return c.json({
success: success
})
})
api.delete('/api/clear_sent_items', async (c) => {
const lang = c.get("lang") || c.env.DEFAULT_LANG;
const msgs = i18n.getMessages(lang);
if (!getBooleanValue(c.env.ENABLE_USER_DELETE_EMAIL)) {
return c.text(msgs.UserDeleteEmailDisabledMsg, 403)
}
const { address } = c.get("jwtPayload")
const { success } = await c.env.DB.prepare(
`DELETE FROM sendbox WHERE address = ?`
).bind(address).run();
if (!success) {
return c.text("Failed to clear sent items", 500)
}
return c.json({
success: success
})
})
+2 -2
View File
@@ -7,7 +7,7 @@ import { commonParseMail, sendWebhook } from "../common";
async function getWebhookSettings(c: Context<HonoCustomType>): Promise<Response> { async function getWebhookSettings(c: Context<HonoCustomType>): Promise<Response> {
const { address } = c.get("jwtPayload") const { address } = c.get("jwtPayload")
const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json"); const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json");
if (!adminSettings?.allowList.includes(address)) { if (adminSettings?.enableAllowList && !adminSettings?.allowList.includes(address)) {
return c.text("Webhook settings is not allowed for this user", 403); return c.text("Webhook settings is not allowed for this user", 403);
} }
const settings = await c.env.KV.get<WebhookSettings>( const settings = await c.env.KV.get<WebhookSettings>(
@@ -20,7 +20,7 @@ async function getWebhookSettings(c: Context<HonoCustomType>): Promise<Response>
async function saveWebhookSettings(c: Context<HonoCustomType>): Promise<Response> { async function saveWebhookSettings(c: Context<HonoCustomType>): Promise<Response> {
const { address } = c.get("jwtPayload") const { address } = c.get("jwtPayload")
const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json"); const adminSettings = await c.env.KV.get<AdminWebhookSettings>(CONSTANTS.WEBHOOK_KV_SETTINGS_KEY, "json");
if (!adminSettings?.allowList.includes(address)) { if (adminSettings?.enableAllowList && !adminSettings?.allowList.includes(address)) {
return c.text("Webhook settings is not allowed for this user", 403); return c.text("Webhook settings is not allowed for this user", 403);
} }
const settings = await c.req.json<WebhookSettings>(); const settings = await c.req.json<WebhookSettings>();
+3 -1
View File
@@ -14,9 +14,11 @@ export type Passkey = {
}; };
export class AdminWebhookSettings { export class AdminWebhookSettings {
enableAllowList: boolean;
allowList: string[]; allowList: string[];
constructor(allowList: string[]) { constructor(enableAllowList: boolean, allowList: string[]) {
this.enableAllowList = enableAllowList;
this.allowList = allowList; this.allowList = allowList;
} }
} }
+15 -8
View File
@@ -1,8 +1,8 @@
import { Context } from "hono"; import { Context } from "hono";
import { Jwt } from "hono/utils/jwt"; import { Jwt } from "hono/utils/jwt";
import { CONSTANTS } from "../constants"; import { CONSTANTS } from "../constants";
import { getIntValue, getJsonSetting } from "../utils"; import { getBooleanValue, getIntValue, getJsonSetting } from "../utils";
import { deleteAddressWithData, newAddress } from "../common"; import { deleteAddressWithData, newAddress, generateRandomName } from "../common";
export const tgUserNewAddress = async ( export const tgUserNewAddress = async (
c: Context<HonoCustomType>, userId: string, address: string c: Context<HonoCustomType>, userId: string, address: string
@@ -15,21 +15,28 @@ export const tgUserNewAddress = async (
throw Error("Rate limit exceeded") throw Error("Rate limit exceeded")
} }
} }
// @ts-ignore // Check if custom address names are disabled
address = address || Math.random().toString(36).substring(2, 15); const disableCustomAddressName = getBooleanValue(c.env.DISABLE_CUSTOM_ADDRESS_NAME);
const [name, domain] = address.includes("@") ? address.split("@") : [address, null];
// Parse address parameter - handle empty or whitespace-only address
const trimmedAddress = address ? address.trim() : "";
const [name, domain] = trimmedAddress.includes("@") ? trimmedAddress.split("@") : [trimmedAddress, null];
const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || []; const jwtList = await c.env.KV.get<string[]>(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, 'json') || [];
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) { if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) {
throw Error("绑定地址数量已达上限"); throw Error("绑定地址数量已达上限");
} }
// Generate name if disabled or not provided
const finalName = (!name || disableCustomAddressName) ? generateRandomName(c) : name;
// check name block list // check name block list
const value = await getJsonSetting(c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY); const value = await getJsonSetting(c, CONSTANTS.ADDRESS_BLOCK_LIST_KEY);
const blockList = (value || []) as string[]; const blockList = (value || []) as string[];
if (blockList.some((item) => name.includes(item))) { if (blockList.some((item) => finalName.includes(item))) {
throw Error(`Name[${name}]is blocked`); throw Error(`Name[${finalName}]is blocked`);
} }
const res = await newAddress(c, { const res = await newAddress(c, {
name: name || Math.random().toString(36).substring(2, 15), name: finalName,
domain, domain,
enablePrefix: true enablePrefix: true
}); });
+1 -1
View File
@@ -18,7 +18,7 @@ const COMMANDS = [
}, },
{ {
command: "new", command: "new",
description: "新建邮箱地址, 如果要自定义邮箱地址, 请输入 /new <name>@<domain>, name [a-z0-9] 有效" description: "新建邮箱地址, 如果要自定义邮箱地址, 请输入 /new, 通过 /new <name>@<domain> 可以指定, name [a-z0-9] 有效, name 为空则随机生成, @<domain> 可选"
}, },
{ {
command: "address", command: "address",
+2
View File
@@ -24,6 +24,8 @@ type Bindings = {
MAX_ADDRESS_LEN: string | number | undefined MAX_ADDRESS_LEN: string | number | undefined
DEFAULT_DOMAINS: string | string[] | undefined DEFAULT_DOMAINS: string | string[] | undefined
DOMAINS: string | string[] | undefined DOMAINS: string | string[] | undefined
DISABLE_CUSTOM_ADDRESS_NAME: string | boolean | undefined
CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST: string | boolean | undefined
ADMIN_USER_ROLE: string | undefined ADMIN_USER_ROLE: string | undefined
USER_DEFAULT_ROLE: string | UserRole | undefined USER_DEFAULT_ROLE: string | UserRole | undefined
USER_ROLES: string | UserRole[] | undefined USER_ROLES: string | UserRole[] | undefined
+4
View File
@@ -35,6 +35,8 @@ PREFIX = "tmp"
# (min, max) length of the adderss, if not set, the default is (1, 30) # (min, max) length of the adderss, if not set, the default is (1, 30)
# MIN_ADDRESS_LEN = 1 # MIN_ADDRESS_LEN = 1
# MAX_ADDRESS_LEN = 30 # MAX_ADDRESS_LEN = 30
# Disable custom email address name, if set true, users cannot input custom email name, will auto generate
# DISABLE_CUSTOM_ADDRESS_NAME = true
# IF YOU WANT TO MAKE YOUR SITE PRIVATE, UNCOMMENT THE FOLLOWING LINES # IF YOU WANT TO MAKE YOUR SITE PRIVATE, UNCOMMENT THE FOLLOWING LINES
# PASSWORDS = ["123", "456"] # PASSWORDS = ["123", "456"]
# For admin panel # For admin panel
@@ -43,6 +45,8 @@ PREFIX = "tmp"
# DISABLE_ADMIN_PASSWORD_CHECK = false # DISABLE_ADMIN_PASSWORD_CHECK = false
# ADMIN CONTACT, CAN BE ANY STRING # ADMIN CONTACT, CAN BE ANY STRING
# ADMIN_CONTACT = "xx@xx.xxx" # ADMIN_CONTACT = "xx@xx.xxx"
# Create new address with default domain first, if set true, will use first domain from DEFAULT_DOMAINS when no domain specified
# CREATE_ADDRESS_DEFAULT_DOMAIN_FIRST = false
DEFAULT_DOMAINS = ["xxx.xxx1" , "xxx.xxx2"] # domain name for no role users DEFAULT_DOMAINS = ["xxx.xxx1" , "xxx.xxx2"] # domain name for no role users
DOMAINS = ["xxx.xxx1" , "xxx.xxx2"] # all domain names DOMAINS = ["xxx.xxx1" , "xxx.xxx2"] # all domain names
# For chinese domain name, you can use DOMAIN_LABELS to show chinese domain name # For chinese domain name, you can use DOMAIN_LABELS to show chinese domain name