import { resend, FROM_EMAIL, APP_NAME } from "./client" export function escapeHtml(value: unknown): string { return String(value ?? "") .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'") } interface SendEmailOptions { to: string subject: string html: string from?: string } export async function sendEmail({ to, subject, html, from }: SendEmailOptions) { const { data, error } = await resend.emails.send({ from: from ?? `${APP_NAME} <${FROM_EMAIL}>`, to, subject, html, }) if (error) { console.error("Email send failed:", error) return { success: false, error } } return { success: true, id: data?.id } } // ── Email templates ────────────────────────────────────────────── export function rentDueReminderHtml({ tenantName, propertyName, unitNumber, amount, dueDate, paymentLink, }: { tenantName: string propertyName: string unitNumber: string amount: string dueDate: string paymentLink?: string }) { return `
Hi ${escapeHtml(tenantName)},
Your rent payment of ${escapeHtml(amount)} for ${escapeHtml(propertyName)} — Unit ${escapeHtml(unitNumber)} is due on ${escapeHtml(dueDate)}.
${paymentLink ? ` Pay Rent Now ` : ""}Property Management Network
Hi ${escapeHtml(tenantName)},
Your rent payment of ${escapeHtml(amount)} for ${escapeHtml(propertyName)} — Unit ${escapeHtml(unitNumber)} was due on ${escapeHtml(dueDate)} and is now overdue. Please make payment as soon as possible.
Property Management Network
Hi ${escapeHtml(tenantName)},
Your lease for ${escapeHtml(propertyName)} — Unit ${escapeHtml(unitNumber)} expires on ${escapeHtml(leaseEnd)} (${escapeHtml(daysLeft)} days from now). Please contact your landlord to discuss renewal.
Property Management Network
Hi ${escapeHtml(tenantName)},
Your maintenance request "${escapeHtml(title)}" has been updated to: ${escapeHtml(status).replace("_", " ")}
${resolutionNotes ? `${escapeHtml(resolutionNotes)}
` : ""}Property Management Network