diff --git a/memento-note/app/(main)/admin/settings/admin-settings-form.tsx b/memento-note/app/(main)/admin/settings/admin-settings-form.tsx index 53152b4..eccb94d 100644 --- a/memento-note/app/(main)/admin/settings/admin-settings-form.tsx +++ b/memento-note/app/(main)/admin/settings/admin-settings-form.tsx @@ -277,8 +277,6 @@ export function AdminSettingsForm({ config }: { config: Record } if (emailProvider === 'resend') { const key = formData.get('RESEND_API_KEY') as string if (key) data.RESEND_API_KEY = key - const from = formData.get('SMTP_FROM') as string - if (from) data.SMTP_FROM = from } else { data.SMTP_HOST = formData.get('SMTP_HOST') as string data.SMTP_PORT = formData.get('SMTP_PORT') as string @@ -302,32 +300,6 @@ export function AdminSettingsForm({ config }: { config: Record } const handleTestEmail = async () => { setIsTesting(true) try { - // Save email config to DB first so test uses the latest values - const emailForm = document.querySelector('form[name="email-form"]') as HTMLFormElement - if (emailForm) { - const formData = new FormData(emailForm) - const saveData: Record = { EMAIL_PROVIDER: emailProvider } - if (emailProvider === 'resend') { - const key = formData.get('RESEND_API_KEY') as string - if (key) saveData.RESEND_API_KEY = key - const from = formData.get('SMTP_FROM') as string - if (from) saveData.SMTP_FROM = from - } else { - saveData.SMTP_HOST = formData.get('SMTP_HOST') as string - saveData.SMTP_PORT = formData.get('SMTP_PORT') as string - saveData.SMTP_USER = formData.get('SMTP_USER') as string - saveData.SMTP_PASS = formData.get('SMTP_PASS') as string - saveData.SMTP_FROM = formData.get('SMTP_FROM') as string - saveData.SMTP_IGNORE_CERT = smtpIgnoreCert ? 'true' : 'false' - saveData.SMTP_SECURE = smtpSecure ? 'true' : 'false' - } - const saveResult = await updateSystemConfig(saveData) - if (saveResult.error) { - toast.error('Failed to save settings before testing: ' + saveResult.error) - setIsTesting(false) - return - } - } const result: any = await testEmail(emailProvider) if (result.success) { toast.success(t('admin.smtp.testSuccess')) @@ -920,7 +892,7 @@ export function AdminSettingsForm({ config }: { config: Record } {t('admin.email.title')} {t('admin.email.description')} -
{ e.preventDefault(); handleSaveEmail(new FormData(e.currentTarget)) }}> + { e.preventDefault(); handleSaveEmail(new FormData(e.currentTarget)) }}>
@@ -985,11 +957,6 @@ export function AdminSettingsForm({ config }: { config: Record }

{t('admin.resend.apiKeyHint')}

-
- - -

Email address used as sender. Must be a domain verified in Resend.

-
{config.RESEND_API_KEY && (
diff --git a/memento-note/lib/mail.ts b/memento-note/lib/mail.ts index 2d6e8ac..409180f 100644 --- a/memento-note/lib/mail.ts +++ b/memento-note/lib/mail.ts @@ -41,12 +41,12 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions, // Force Resend (no fallback) if (provider === 'resend') { if (!resendKey) return { success: false, error: 'No Resend API key configured' }; - return sendViaResend(resendKey, config, { to, subject, html, attachments }); + return sendViaResend(resendKey, { to, subject, html, attachments }); } // Auto: try Resend, fall back to SMTP if (resendKey) { - const result = await sendViaResend(resendKey, config, { to, subject, html, attachments }); + const result = await sendViaResend(resendKey, { to, subject, html, attachments }); if (result.success) return result; console.warn('[Mail] Resend failed, falling back to SMTP:', result.error); @@ -56,28 +56,14 @@ export async function sendEmail({ to, subject, html, attachments }: MailOptions, return sendViaSMTP(config, { to, subject, html, attachments }); } -async function sendViaResend(apiKey: string, config: Record, { to, subject, html, attachments }: MailOptions): Promise { +async function sendViaResend(apiKey: string, { to, subject, html, attachments }: MailOptions): Promise { try { const { Resend } = await import('resend'); const resend = new Resend(apiKey); - // Build a valid "from" address for Resend - // Priority: SMTP_FROM from DB config > env var > derived from NEXTAUTH_URL > Resend default - const smtpFrom = config.SMTP_FROM || process.env.SMTP_FROM; - let from: string; - if (smtpFrom) { - from = smtpFrom.includes('<') ? smtpFrom : `Memento <${smtpFrom}>`; - } else if (process.env.NEXTAUTH_URL) { - const hostname = new URL(process.env.NEXTAUTH_URL).hostname; - // Only use hostname-based from if it's not localhost (Resend rejects it) - if (hostname !== 'localhost') { - from = `Memento `; - } else { - from = 'Memento '; - } - } else { - from = 'Memento '; - } + const from = process.env.NEXTAUTH_URL + ? `Memento ` + : 'Memento '; // Resend supports attachments with inline content const resendAttachments = attachments?.map(att => ({