import { config } from '../config.js'; type WelcomeRecipient = { name: string; email: string }; export async function sendWelcomeEmail(recipient: WelcomeRecipient) { if (!config.RESEND_API_KEY || !config.EMAIL_FROM) return false; const escapedName = recipient.name.replace(/[&<>"']/g, (character) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[character] || character)); const response = await fetch('https://api.resend.com/emails', { method: 'POST', headers: { Authorization: `Bearer ${config.RESEND_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ from: config.EMAIL_FROM, to: [recipient.email], subject: 'Bem-vindo(a) ao Compor HUB', html: `

Bem-vindo(a), ${escapedName}!

Sua conta no Compor HUB já está pronta.

Agora você pode acessar cursos, acompanhar suas aulas e baixar materiais complementares.

Acessar Compor HUB

`, }), }); return response.ok; }