// Email template for user sign-in. Body contains a 6-digit code only — the // magic-link path is still wired (see /verify/[token] and the EmailProvider // callback) but the URL is intentionally omitted from the email to reduce // the content-scanner surface area for corporate email gateways. import { createTransport } from "nodemailer"; import { buildMailHeaders } from "./buildMailHeaders"; export async function MagicLinksEmail({ identifier, url, provider, code, }: { identifier: string; url: string; provider: { server: any; from: string }; code: string; }): Promise<{ messageId: string }> { const parsed = new URL(url); const host = parsed.host; const logoUrl = `${parsed.origin}/domna-email-logo.png`; const transport = createTransport(provider.server); const brandColor = "#14163d"; const accentColor = "#2d348f"; const background = "#F9F9F9"; const result = await transport.sendMail({ to: identifier, from: provider.from, subject: "Sign in to Ara", text: plainText({ code, host }), html: domnaHtml({ code, logoUrl, host, brandColor, accentColor, background, }), headers: buildMailHeaders({ fromAddress: provider.from, sesConfigurationSet: process.env.SES_CONFIGURATION_SET, }), }); const failed = result.rejected.filter(Boolean); if (failed.length) { throw new Error(`Email(s) (${failed.join(", ")}) could not be sent`); } return { messageId: result.messageId }; } function formatCodeForDisplay(code: string): string { // Insert a non-breaking space for readability without breaking copy-paste // semantics in mail clients that strip the visual grouping. return `${code.slice(0, 3)} ${code.slice(3)}`; } function domnaHtml({ code, logoUrl, host, brandColor, accentColor, background, }: { code: string; logoUrl: string; host: string; brandColor: string; accentColor: string; background: string; }) { const escapedHost = host.replace(/\./g, "​."); const codeDisplay = formatCodeForDisplay(code); return `
Domna Logo

Your sign-in code

Enter this code at ${escapedHost} to sign in to Ara.

${codeDisplay}

This code expires in 10 minutes.

If you didn’t request this email, you can safely ignore it.

© ${new Date().getFullYear()} Domna Homes • ${escapedHost}
`; } function plainText({ code, host }: { code: string; host: string }) { return `Sign in to Ara by Domna Your sign-in code: ${code} Enter this code at ${host}/auth/verify-code to sign in. This code expires in 10 minutes. If you did not request this email, you can safely ignore it. `; }