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