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
|
||||
environment:
|
||||
- TZ=Europe/Berlin
|
||||
- BREVO_KEY=${BREVO_KEY}
|
||||
networks:
|
||||
- default
|
||||
- npm_bridge
|
||||
|
|
|
|||
|
|
@ -1,59 +1,39 @@
|
|||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// Sendet eine Benachrichtigungs-Mail bei neuer Demo-Anfrage
|
||||
onRecordCreate((e) => {
|
||||
e.next();
|
||||
|
||||
onRecordAfterCreateSuccess(function(e) {
|
||||
if (e.collection.name !== "inquiries") return;
|
||||
|
||||
const r = e.record;
|
||||
const name = r.getString("name");
|
||||
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");
|
||||
var key = $os.getenv("BREVO_KEY");
|
||||
if (!key) { console.error("BREVO_KEY nicht gesetzt"); return; }
|
||||
|
||||
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 = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head><meta charset="utf-8"></head>
|
||||
<body style="font-family:sans-serif;background:#f5f7fa;margin:0;padding:0">
|
||||
<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)">
|
||||
<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>`;
|
||||
var subject = "checkflo: Neue Anfrage von " + name + (company ? " (" + company + ")" : "");
|
||||
var text = "Von: " + name + (company ? " / " + company : "") +
|
||||
"\nEmail: " + email +
|
||||
(phone ? "\nTel: " + phone : "") +
|
||||
(plan ? "\nPlan: " + plan : "") +
|
||||
(message ? "\nNachricht: " + message : "");
|
||||
|
||||
try {
|
||||
const message = new MailerMessage({
|
||||
from: { address: "hallo@checkflo.de", name: "checkflo" },
|
||||
to: [{ address: "checkflo@motocamp.de" }],
|
||||
$http.send({
|
||||
url: "https://api.brevo.com/v3/smtp/email",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"api-key": key,
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
sender: { name: "checkflo", email: "hallo@checkflo.de" },
|
||||
to: [{ email: "checkflo@motocamp.de" }],
|
||||
subject: subject,
|
||||
html: html,
|
||||
textContent: text
|
||||
})
|
||||
});
|
||||
$app.newMailClient().send(message);
|
||||
} catch(err) {
|
||||
console.error("Inquiry-Mail Fehler:", err);
|
||||
console.error("Brevo error: " + String(err));
|
||||
}
|
||||
});
|
||||
}, "inquiries");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue