Compare commits

..

No commits in common. "3fd64368a26c78c6e1afa70a70cb50ff88185391" and "144ce428f0cad1ea1c68d3e28b402d546f8d3e5b" have entirely different histories.

1 changed files with 16 additions and 21 deletions

View File

@ -80,29 +80,24 @@ export async function sendEmailCf(data: Record<string, string>, to: string, type
const apiToken = import.meta.env.CLOUDFLARE_API_TOKEN;
const accountId = import.meta.env.CLOUDFLARE_ACCOUNT_ID;
try {
const client = new Cloudflare({ apiToken });
const { subject } = TEMPLATE_URLS[type];
const rawHtml = await fetchTemplate(type);
const html = renderTemplate(rawHtml, data);
const text = stripHtml(html);
const client = new Cloudflare({ apiToken });
const { subject } = TEMPLATE_URLS[type];
const rawHtml = await fetchTemplate(type);
const html = renderTemplate(rawHtml, data);
const text = stripHtml(html);
const response = await client.emailSending.send({
account_id: accountId,
from: "welcome@mail.centrodelreinodepazyjusticia.com",
to,
subject,
html,
text,
});
const response = await client.emailSending.send({
account_id: accountId,
from: "welcome@mail.centrodelreinodepazyjusticia.com",
to,
subject,
html,
text,
});
if (response.permanent_bounces.includes(to)) {
console.error("Cloudflare email not delivered", response);
throw new Error("El correo no fue entregado");
}
} catch (error) {
console.error("Cloudflare email failed, fallback a n8n:", error);
await sendEmail(data, to, type);
if (response.permanent_bounces.includes(to)) {
console.error("Cloudflare email not delivered", response);
throw new Error("El correo no fue entregado");
}
}