export type SendSignupEmailInput = { apiKey: string; from: string; to: string; verifyUrl: string; expiresAt: Date; }; export async function sendSignupEmail(input: SendSignupEmailInput): Promise { const expires = input.expiresAt.toLocaleString("en-US", { timeZone: "UTC", dateStyle: "medium", timeStyle: "short", }); const text = [ "Your ditto.site API key is almost ready.", "", `Open this link to verify your email and reveal your key: ${input.verifyUrl}`, "", `This link expires at ${expires} UTC.`, "If you did not request this, you can ignore this email.", ].join("\n"); const html = `

Your ditto.site API key is almost ready.

Open the link below to verify your email and reveal your key.

Verify and get key

This link expires at ${expires} UTC.

If you did not request this, you can ignore this email.

`; const res = await fetch("https://api.resend.com/emails", { method: "POST", headers: { authorization: `Bearer ${input.apiKey}`, "content-type": "application/json", }, body: JSON.stringify({ from: input.from, to: input.to, subject: "Verify your ditto.site API key", text, html, }), }); if (!res.ok) { const detail = await res.text().catch(() => ""); throw new Error(`Resend send failed (${res.status}): ${detail.slice(0, 500)}`); } }