Fix: Brevo via REST API ($http.send), Key als BREVO_KEY Env-Variable
This commit is contained in:
parent
20029b08c5
commit
ba844bc7a2
2 changed files with 32 additions and 51 deletions
|
|
@ -11,6 +11,7 @@ services:
|
||||||
- /volume1/docker/checkflo/pocketbase/data/pb_hooks:/pb_hooks
|
- /volume1/docker/checkflo/pocketbase/data/pb_hooks:/pb_hooks
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Berlin
|
- TZ=Europe/Berlin
|
||||||
|
- BREVO_KEY=${BREVO_KEY}
|
||||||
networks:
|
networks:
|
||||||
- default
|
- default
|
||||||
- npm_bridge
|
- npm_bridge
|
||||||
|
|
|
||||||
|
|
@ -1,59 +1,39 @@
|
||||||
/// <reference path="../pb_data/types.d.ts" />
|
onRecordAfterCreateSuccess(function(e) {
|
||||||
|
|
||||||
// Sendet eine Benachrichtigungs-Mail bei neuer Demo-Anfrage
|
|
||||||
onRecordCreate((e) => {
|
|
||||||
e.next();
|
|
||||||
|
|
||||||
if (e.collection.name !== "inquiries") return;
|
if (e.collection.name !== "inquiries") return;
|
||||||
|
|
||||||
const r = e.record;
|
var key = $os.getenv("BREVO_KEY");
|
||||||
const name = r.getString("name");
|
if (!key) { console.error("BREVO_KEY nicht gesetzt"); return; }
|
||||||
const company = r.getString("company");
|
|
||||||
const email = r.getString("email");
|
|
||||||
const phone = r.getString("phone");
|
|
||||||
const message = r.getString("message");
|
|
||||||
const plan = r.getString("plan");
|
|
||||||
|
|
||||||
const subject = `checkflo: Neue Anfrage von ${name}${company ? " (" + company + ")" : ""}`;
|
var name = e.record.getString("name");
|
||||||
|
var company = e.record.getString("company");
|
||||||
|
var email = e.record.getString("email");
|
||||||
|
var phone = e.record.getString("phone");
|
||||||
|
var message = e.record.getString("message");
|
||||||
|
var plan = e.record.getString("plan");
|
||||||
|
|
||||||
const html = `
|
var subject = "checkflo: Neue Anfrage von " + name + (company ? " (" + company + ")" : "");
|
||||||
<!DOCTYPE html>
|
var text = "Von: " + name + (company ? " / " + company : "") +
|
||||||
<html lang="de">
|
"\nEmail: " + email +
|
||||||
<head><meta charset="utf-8"></head>
|
(phone ? "\nTel: " + phone : "") +
|
||||||
<body style="font-family:sans-serif;background:#f5f7fa;margin:0;padding:0">
|
(plan ? "\nPlan: " + plan : "") +
|
||||||
<div style="max-width:560px;margin:32px auto;background:#fff;border-radius:12px;padding:32px;box-shadow:0 2px 8px rgba(0,0,0,.08)">
|
(message ? "\nNachricht: " + message : "");
|
||||||
<div style="margin-bottom:24px">
|
|
||||||
<span style="background:#0B1023;color:#F97316;padding:6px 14px;border-radius:20px;font-size:12px;font-weight:700;letter-spacing:1px">NEUE DEMO-ANFRAGE</span>
|
|
||||||
</div>
|
|
||||||
<h2 style="color:#0B1023;margin:0 0 4px">${name}</h2>
|
|
||||||
${company ? `<p style="color:#888;margin:0 0 20px;font-size:14px">${company}</p>` : `<div style="margin-bottom:20px"></div>`}
|
|
||||||
|
|
||||||
<table style="width:100%;border-collapse:collapse;font-size:14px">
|
|
||||||
<tr><td style="padding:8px 0;color:#888;width:100px">E-Mail</td><td style="padding:8px 0;color:#0B1023"><a href="mailto:${email}" style="color:#F97316">${email}</a></td></tr>
|
|
||||||
${phone ? `<tr><td style="padding:8px 0;color:#888">Telefon</td><td style="padding:8px 0;color:#0B1023">${phone}</td></tr>` : ""}
|
|
||||||
${plan ? `<tr><td style="padding:8px 0;color:#888">Plan</td><td style="padding:8px 0;color:#0B1023;font-weight:600">${plan}</td></tr>` : ""}
|
|
||||||
${message ? `<tr><td style="padding:8px 0;color:#888;vertical-align:top">Nachricht</td><td style="padding:8px 0;color:#0B1023">${message}</td></tr>` : ""}
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<div style="margin-top:28px;padding-top:20px;border-top:1px solid #eee">
|
|
||||||
<a href="https://api.checkflo.de/_/#/collections/inquiries"
|
|
||||||
style="background:#F97316;color:#fff;padding:12px 24px;border-radius:8px;text-decoration:none;font-weight:700;font-size:14px">
|
|
||||||
Alle Anfragen in PocketBase →
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = new MailerMessage({
|
$http.send({
|
||||||
from: { address: "hallo@checkflo.de", name: "checkflo" },
|
url: "https://api.brevo.com/v3/smtp/email",
|
||||||
to: [{ address: "checkflo@motocamp.de" }],
|
method: "POST",
|
||||||
subject: subject,
|
headers: {
|
||||||
html: html,
|
"api-key": key,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
sender: { name: "checkflo", email: "hallo@checkflo.de" },
|
||||||
|
to: [{ email: "checkflo@motocamp.de" }],
|
||||||
|
subject: subject,
|
||||||
|
textContent: text
|
||||||
|
})
|
||||||
});
|
});
|
||||||
$app.newMailClient().send(message);
|
} catch(err) {
|
||||||
} catch (err) {
|
console.error("Brevo error: " + String(err));
|
||||||
console.error("Inquiry-Mail Fehler:", err);
|
|
||||||
}
|
}
|
||||||
});
|
}, "inquiries");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue