From 51c62715a5794f037f6be838cedfa4aae729ff2b Mon Sep 17 00:00:00 2001 From: wangliang Date: Fri, 23 Oct 2026 12:26:23 +0800 Subject: [PATCH] fix: allow email inbox setup from SMTP env without old mail config --- .gitignore | 2 ++ scripts/add-email-inbox.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 54cc95a..0712ab3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ var/ # 子项目自带的 git 历史 libredesk/.git/ + +.agent-credentials diff --git a/scripts/add-email-inbox.js b/scripts/add-email-inbox.js index 09be191..229e7b3 100644 --- a/scripts/add-email-inbox.js +++ b/scripts/add-email-inbox.js @@ -78,7 +78,17 @@ const data = (j) => (j && j.data !== undefined ? j.data : j); async function main() { const env = loadEnv(path.join(ROOT, '.env')); - const old = JSON.parse(fs.readFileSync(OLD_MAIL_CFG, 'utf8')); + const old = fs.existsSync(OLD_MAIL_CFG) + ? JSON.parse(fs.readFileSync(OLD_MAIL_CFG, 'utf8')) + : { + imap: { auth: { user: env.SMTP_USER, pass: env.SMTP_PASS } }, + smtp: { + host: env.SMTP_HOST || 'smtp.163.com', + port: Number(env.SMTP_PORT || 465), + auth: { user: env.SMTP_USER, pass: env.SMTP_PASS }, + }, + }; + if (!old.imap?.auth?.user || !old.imap?.auth?.pass) throw new Error('缺少 IMAP/SMTP 凭据(设置 SMTP_USER/SMTP_PASS 或提供旧 mail.config.json)'); const base = (env.LIBREDESK_BASE_URL || 'http://localhost:9000').replace(/\/+$/, ''); const c = createClient(base); await c.post('/api/v1/auth/login', { email: env.LIBREDESK_SYSTEM_EMAIL || 'System', password: env.LIBREDESK_SYSTEM_USER_PASSWORD });