feat(mail): use branded HTML template with personalized greeting (Gitea #21)

GDPR export emails were unstyled HTML with a bare "Hallo," greeting.
Adds a landing-page-branded email shell (orange gradient header, paw
wordmark) and pulls the owner's first name from their Clerk profile
for the salutation, falling back to "Hallo," when unavailable.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Sonnet 5 committed 2026-08-13 15:13:08 +02:00
1 parent f0a878c432
commit 19f22102df
3 files changed
+122 -2

No files matched your search

+10
View File
@@ -102,3 +102,13 @@ Despite `next.config.ts`'s `output: "standalone"` and the original stack researc
- `pentest-ai-agents/` — a separately-cloned plugin repo (has its own `.git`) sitting inside this project root. Unrelated to PawFeed; don't treat its `agents/`, `commands/`, `db/` as part of the app.
- `scaffold-tmp/` — leftover `create-next-app` scaffold from initial bootstrap (has its own `package.json`, `node_modules`, generic starter page). Not part of the running app, which lives under `src/`.
<!-- BEGIN:nextjs-agent-rules -->
# This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
<!-- END:nextjs-agent-rules -->
+102
View File
@@ -0,0 +1,102 @@
import "server-only";
/**
* Branded HTML shell for transactional emails, mirroring the landing page's
* orange gradient hero + paw-print wordmark (src/app/page.tsx) so PawFeed
* mail doesn't look like unstyled plaintext dumped into an HTML wrapper
* (Gitea report: "html plain" emails with a bare "Hallo," greeting).
*
* Table-based layout with inline styles throughout — email clients (Outlook
* especially) ignore most <style> block CSS and flexbox/grid entirely, so
* this deliberately avoids Tailwind classes and modern layout properties.
*/
interface BrandedMailInput {
previewText: string;
greetingName?: string | null;
bodyHtml: string;
ctaLabel?: string;
ctaUrl?: string;
}
const ORANGE_500 = "#f97316";
const ORANGE_600 = "#ea580c";
const ORANGE_50 = "#fff7ed";
const TEXT_MUTED = "#78716c";
const TEXT_BODY = "#292524";
export function buildGreeting(firstName?: string | null): string {
return firstName ? `Hallo ${firstName},` : "Hallo,";
}
export function renderBrandedMailHtml({
previewText,
greetingName,
bodyHtml,
ctaLabel,
ctaUrl,
}: BrandedMailInput): string {
const greeting = buildGreeting(greetingName);
const cta =
ctaLabel && ctaUrl
? `
<tr>
<td style="padding: 8px 40px 32px;">
<table role="presentation" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="border-radius: 10px; background-color: ${ORANGE_500};">
<a href="${ctaUrl}" style="display: inline-block; padding: 13px 28px; font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 15px; font-weight: 600; color: #ffffff; text-decoration: none;">
${ctaLabel}
</a>
</td>
</tr>
</table>
</td>
</tr>`
: "";
return `<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>PawFeed</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f5f5f4;">
<div style="display: none; max-height: 0; overflow: hidden; opacity: 0;">${previewText}</div>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color: #f5f5f4; padding: 32px 16px;">
<tr>
<td align="center">
<table role="presentation" width="600" cellpadding="0" cellspacing="0" border="0" style="max-width: 600px; width: 100%; background-color: #ffffff; border-radius: 20px; overflow: hidden;">
<tr>
<td style="background-color: ${ORANGE_500}; padding: 36px 40px;" align="center">
<div style="font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 26px; font-weight: 800; color: #ffffff; letter-spacing: -0.02em;">
🐾&nbsp;&nbsp;PawFeed
</div>
<div style="font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 500; color: ${ORANGE_50}; margin-top: 6px;">
Where pets are the stars.
</div>
</td>
</tr>
<tr>
<td style="padding: 36px 40px 8px; font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 16px; line-height: 1.6; color: ${TEXT_BODY};">
<p style="margin: 0 0 16px;">${greeting}</p>
${bodyHtml}
</td>
</tr>
${cta}
<tr>
<td style="padding: 24px 40px 32px; border-top: 1px solid #f0efed;">
<p style="margin: 0; font-family: 'Segoe UI', Helvetica, Arial, sans-serif; font-size: 13px; line-height: 1.6; color: ${TEXT_MUTED};">
Dein PawFeed-Team<br />
Diese E-Mail wurde automatisch von <a href="https://pawfeed.org" style="color: ${ORANGE_600}; text-decoration: none;">pawfeed.org</a> versendet.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>`;
}
+10 -2
View File
@@ -13,6 +13,7 @@ import {
import { buildDataExport } from "@/lib/gdpr-export";
import { uploadExport } from "@/lib/data-export-storage";
import { sendMail } from "@/lib/mail";
import { buildGreeting, renderBrandedMailHtml } from "@/lib/mail-template";
import { deleteOwnerAccount } from "@/lib/delete-account";
import { ensureTeamPet, sendTeamMessage } from "@/lib/team-pet";
import { matchesWordBlacklist, matchesLinkBlacklist } from "@/lib/blacklist";
@@ -1160,12 +1161,19 @@ export const adminRouter = router({
},
});
const downloadUrl = `${process.env.NEXT_PUBLIC_APP_URL}/api/gdpr-export/${exportToken.token}`;
const firstName = exportData.account.clerkProfile?.firstName ?? null;
await sendMail({
to: email,
subject: "Deine Daten bei PawFeed — Auskunft gemäß Art. 15 DSGVO",
text: `Hallo,\n\nanbei der Link zu deiner Datenauskunft gemäß Art. 15 DSGVO. Der Link ist 7 Tage gültig:\n\n${downloadUrl}\n\nBei Fragen antworte einfach auf diese E-Mail.\n\nDein PawFeed-Team`,
html: `<p>Hallo,</p><p>anbei der Link zu deiner Datenauskunft gemäß Art. 15 DSGVO. Der Link ist <strong>7 Tage</strong> gültig:</p><p><a href="${downloadUrl}">${downloadUrl}</a></p><p>Bei Fragen antworte einfach auf diese E-Mail.</p><p>Dein PawFeed-Team</p>`,
text: `${buildGreeting(firstName)}\n\nanbei der Link zu deiner Datenauskunft gemäß Art. 15 DSGVO. Der Link ist 7 Tage gültig:\n\n${downloadUrl}\n\nBei Fragen antworte einfach auf diese E-Mail.\n\nDein PawFeed-Team`,
html: renderBrandedMailHtml({
previewText: "Dein Datenauskunft-Link gemäß Art. 15 DSGVO ist bereit.",
greetingName: firstName,
bodyHtml: `<p style="margin: 0 0 16px;">anbei der Link zu deiner Datenauskunft gemäß Art. 15 DSGVO. Der Link ist <strong>7 Tage</strong> gültig.</p><p style="margin: 0;">Bei Fragen antworte einfach auf diese E-Mail.</p>`,
ctaLabel: "Daten herunterladen",
ctaUrl: downloadUrl,
}),
});
await ctx.prisma.moderationLog.create({