Email marketing

This commit is contained in:
2026-07-29 00:02:50 +02:00
parent e1b6d5fcc1
commit 11fdec610f
6 changed files with 379 additions and 19 deletions

View File

@@ -567,7 +567,9 @@ export async function sendDesignerAnnouncementEmail(email: string, unsubscribeUr
const createUrl = `${appUrl}/create`;
await resend.emails.send({
const transport = createSmtpTransport();
await transport.sendMail({
from: 'Timo from QR Master <timo@qrmaster.net>',
replyTo: 'support@qrmaster.net',
to: email,
@@ -601,6 +603,47 @@ export async function sendDesignerAnnouncementEmail(email: string, unsubscribeUr
text: `Your QR codes can now look like your brand. Design your QR code: ${createUrl}\n\nUnsubscribe from product updates: ${unsubscribeUrl}`,
});
}
function escapeHtml(value: string) {
return value.replace(/[&<>"']/g, (character) => ({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
})[character] as string);
}
export async function sendNewsletterEmail({
email,
subject,
content,
format,
unsubscribeUrl,
}: {
email: string;
subject: string;
content: string;
format: 'text' | 'html';
unsubscribeUrl: string;
}) {
await waitForRateLimit();
const body = format === 'html'
? content
: `<div style="white-space:pre-wrap;">${escapeHtml(content)}</div>`;
const transport = createSmtpTransport();
await transport.sendMail({
from: 'Timo from QR Master <timo@qrmaster.net>',
replyTo: 'support@qrmaster.net',
to: email,
subject,
html: `<!doctype html><html><body style="margin:0;background:#f5f4ef;color:#1b1c19;font-family:Arial,sans-serif;"><table role="presentation" width="100%" cellspacing="0" cellpadding="0"><tr><td align="center" style="padding:32px 12px;"><table role="presentation" width="600" cellspacing="0" cellpadding="0" style="width:100%;max-width:600px;background:#fff;"><tr><td style="padding:20px 32px;border-bottom:1px solid #e3e3de;font-size:11px;font-weight:bold;letter-spacing:2px;">QR MASTER</td></tr><tr><td style="padding:36px 32px;">${body}</td></tr><tr><td style="padding:20px 32px;border-top:1px solid #e3e3de;color:#747878;font-size:11px;line-height:1.6;">You are receiving this email from QR Master.<br><a href="${unsubscribeUrl}" style="color:#747878;">Unsubscribe from product updates</a></td></tr></table></td></tr></table></body></html>`,
text: format === 'text' ? `${content}\n\nUnsubscribe: ${unsubscribeUrl}` : `View this email in HTML. Unsubscribe: ${unsubscribeUrl}`,
});
}
// ---------------------------------------------------------------------------
// Shared design tokens (email-safe inline styles)