From 054d75d0275d991d69df9e8a4dcfad7cfc293490 Mon Sep 17 00:00:00 2001 From: anghunk Date: Mon, 19 Jan 2026 17:54:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(getAdminNotifyEmail):=20=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E9=82=AE=E7=AE=B1=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cwd-comments-api/src/utils/email.ts | 37 ++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/cwd-comments-api/src/utils/email.ts b/cwd-comments-api/src/utils/email.ts index 429a489..6850448 100644 --- a/cwd-comments-api/src/utils/email.ts +++ b/cwd-comments-api/src/utils/email.ts @@ -120,12 +120,25 @@ export async function sendCommentNotification( return; } - await env.SEND_EMAIL.send({ - to: [{ email: toEmail }], - from: { email: env.CF_FROM_EMAIL }, - subject: `新评论通知:${postTitle}`, - html + console.log('EmailAdminNotification:send:start', { + to: toEmail, + from: env.CF_FROM_EMAIL }); + try { + await env.SEND_EMAIL.send({ + to: [toEmail], + from: env.CF_FROM_EMAIL, + subject: `新评论通知:${postTitle}`, + html + }); + } catch (sendError: any) { + console.error('EmailAdminNotification:send:error', { + error: sendError.message, + to: toEmail, + from: env.CF_FROM_EMAIL + }); + throw sendError; + } console.log('EmailAdminNotification:sent', { toEmail @@ -140,16 +153,22 @@ async function getAdminNotifyEmail(env: Bindings): Promise { .bind('admin_notify_email') .first<{ value: string }>(); if (row?.value && isValidEmail(row.value)) { + const cleanEmail = row.value.trim(); console.log('EmailAdminNotification:useDbEmail', { - email: row.value + email: cleanEmail, + originalLength: row.value.length, + cleanLength: cleanEmail.length }); - return row.value; + return cleanEmail; } if (env.EMAIL_ADDRESS && isValidEmail(env.EMAIL_ADDRESS)) { + const cleanEmail = env.EMAIL_ADDRESS.trim(); console.log('EmailAdminNotification:useEnvEmail', { - email: env.EMAIL_ADDRESS + email: cleanEmail, + originalLength: env.EMAIL_ADDRESS.length, + cleanLength: cleanEmail.length }); - return env.EMAIL_ADDRESS; + return cleanEmail; } console.error('EmailAdminNotification:noAdminEmail', { dbValue: row?.value,