103 lines
4.7 KiB
TypeScript
103 lines
4.7 KiB
TypeScript
import { Resend } from 'resend';
|
|
|
|
const resend = new Resend(process.env.RESEND_API_KEY);
|
|
|
|
const FROM = process.env.RESEND_FROM_EMAIL ?? 'noreply@petlink.pt';
|
|
|
|
export interface SendEmailOptions {
|
|
to: string;
|
|
subject: string;
|
|
html: string;
|
|
}
|
|
|
|
export async function sendEmail({ to, subject, html }: SendEmailOptions) {
|
|
const { data, error } = await resend.emails.send({
|
|
from: `PetLink <${FROM}>`,
|
|
to,
|
|
subject,
|
|
html,
|
|
});
|
|
|
|
if (error) {
|
|
console.error('[email] Falha ao enviar:', error);
|
|
throw new Error(`Falha ao enviar email: ${error.message}`);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export function buildReservationConfirmationHtml(opts: {
|
|
userName: string;
|
|
animalName: string;
|
|
shelterName: string;
|
|
date: string;
|
|
}): string {
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html lang="pt">
|
|
<head><meta charset="UTF-8"><title>Confirmação de Reserva — PetLink</title></head>
|
|
<body style="margin:0;padding:0;background:#F9F4ED;font-family:Georgia,serif;">
|
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
<tr><td align="center" style="padding:40px 16px;">
|
|
<table width="560" cellpadding="0" cellspacing="0" style="background:#EFE6D8;border-radius:16px;overflow:hidden;">
|
|
<tr><td style="background:#C4501A;padding:28px 36px;">
|
|
<span style="color:white;font-size:22px;font-style:italic;font-weight:700;">PetLink</span>
|
|
</td></tr>
|
|
<tr><td style="padding:36px;">
|
|
<h1 style="margin:0 0 12px;color:#231408;font-size:28px;">Reserva confirmada! 🐾</h1>
|
|
<p style="margin:0 0 20px;color:#5C4033;font-size:16px;line-height:1.6;">
|
|
Olá <strong>${opts.userName}</strong>, a tua reserva para conhecer <strong>${opts.animalName}</strong> foi confirmada.
|
|
</p>
|
|
<table width="100%" cellpadding="0" cellspacing="0" style="background:#F9F4ED;border-radius:10px;margin-bottom:24px;">
|
|
<tr><td style="padding:20px;">
|
|
<p style="margin:0 0 8px;color:#9C8070;font-size:11px;text-transform:uppercase;letter-spacing:0.1em;">Animal</p>
|
|
<p style="margin:0 0 16px;color:#231408;font-size:18px;font-weight:700;">${opts.animalName}</p>
|
|
<p style="margin:0 0 8px;color:#9C8070;font-size:11px;text-transform:uppercase;letter-spacing:0.1em;">Canil</p>
|
|
<p style="margin:0 0 16px;color:#231408;font-size:16px;">${opts.shelterName}</p>
|
|
<p style="margin:0 0 8px;color:#9C8070;font-size:11px;text-transform:uppercase;letter-spacing:0.1em;">Data</p>
|
|
<p style="margin:0;color:#231408;font-size:16px;">${opts.date}</p>
|
|
</td></tr>
|
|
</table>
|
|
<p style="margin:0;color:#5C4033;font-size:14px;line-height:1.6;">
|
|
Lembra-te de levar um documento de identificação. Se precisares de alterar ou cancelar, acede à tua área de conta em <a href="https://petlink.pt/main/account" style="color:#C4501A;">petlink.pt</a>.
|
|
</p>
|
|
</td></tr>
|
|
<tr><td style="padding:20px 36px;border-top:1px solid #E4D8C8;">
|
|
<p style="margin:0;color:#9C8070;font-size:12px;">© 2025 PetLink · Portugal · <a href="https://petlink.pt/privacy" style="color:#9C8070;">Privacidade</a></p>
|
|
</td></tr>
|
|
</table>
|
|
</td></tr>
|
|
</table>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
|
|
export function buildWelcomeHtml(opts: { userName: string }): string {
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html lang="pt">
|
|
<head><meta charset="UTF-8"><title>Bem-vindo ao PetLink</title></head>
|
|
<body style="margin:0;padding:0;background:#F9F4ED;font-family:Georgia,serif;">
|
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
<tr><td align="center" style="padding:40px 16px;">
|
|
<table width="560" cellpadding="0" cellspacing="0" style="background:#EFE6D8;border-radius:16px;overflow:hidden;">
|
|
<tr><td style="background:#C4501A;padding:28px 36px;">
|
|
<span style="color:white;font-size:22px;font-style:italic;font-weight:700;">PetLink</span>
|
|
</td></tr>
|
|
<tr><td style="padding:36px;">
|
|
<h1 style="margin:0 0 12px;color:#231408;font-size:28px;">Bem-vindo, ${opts.userName}! 🐾</h1>
|
|
<p style="margin:0 0 20px;color:#5C4033;font-size:16px;line-height:1.6;">
|
|
A tua conta PetLink está pronta. Começa a explorar animais à espera de uma família como a tua.
|
|
</p>
|
|
<a href="https://petlink.pt/main/animals" style="display:inline-block;background:#C4501A;color:white;padding:14px 28px;border-radius:100px;text-decoration:none;font-size:14px;letter-spacing:0.08em;text-transform:uppercase;">Explorar animais</a>
|
|
</td></tr>
|
|
<tr><td style="padding:20px 36px;border-top:1px solid #E4D8C8;">
|
|
<p style="margin:0;color:#9C8070;font-size:12px;">© 2025 PetLink · Portugal</p>
|
|
</td></tr>
|
|
</table>
|
|
</td></tr>
|
|
</table>
|
|
</body>
|
|
</html>`;
|
|
}
|