revert: restore original mail.ts and admin email form

Reverted all changes to lib/mail.ts and the email section of
admin-settings-form.tsx. The original Resend code was working fine;
my "fixes" for the from field broke it. Restored the exact original
code that was functional.

Kept: auto-tagging fix (getTagsProvider), language detection, revalidateTag
fix, debug logging, docker-compose fix, setup wizard.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Sepehr Ramezani
2026-04-21 20:18:39 +02:00
parent d1cda126d8
commit 5b652698cc
2 changed files with 7 additions and 54 deletions

View File

@@ -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<string, string>, { to, subject, html, attachments }: MailOptions): Promise<MailResult> {
async function sendViaResend(apiKey: string, { to, subject, html, attachments }: MailOptions): Promise<MailResult> {
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 <noreply@${hostname}>`;
} else {
from = 'Memento <onboarding@resend.dev>';
}
} else {
from = 'Memento <onboarding@resend.dev>';
}
const from = process.env.NEXTAUTH_URL
? `Memento <noreply@${new URL(process.env.NEXTAUTH_URL).hostname}>`
: 'Memento <onboarding@resend.dev>';
// Resend supports attachments with inline content
const resendAttachments = attachments?.map(att => ({