36 lines
1.5 KiB
JavaScript
36 lines
1.5 KiB
JavaScript
onRecordAfterCreateSuccess(function(e) {
|
|
if (!e.record) return;
|
|
|
|
var key = $os.getenv("BREVO_KEY");
|
|
if (!key) return;
|
|
|
|
var name = e.record.getString("name").replace(/"/g, "'");
|
|
var company = e.record.getString("company").replace(/"/g, "'");
|
|
var email = e.record.getString("email").replace(/"/g, "'");
|
|
var phone = e.record.getString("phone").replace(/"/g, "'");
|
|
var message = e.record.getString("message").replace(/"/g, "'");
|
|
var plan = e.record.getString("plan").replace(/"/g, "'");
|
|
|
|
var subject = "checkflo: Anfrage von " + name + (company ? " (" + company + ")" : "");
|
|
var text = "Von: " + name + (company ? " / " + company : "") +
|
|
"\nEmail: " + email +
|
|
(phone ? "\nTel: " + phone : "") +
|
|
(plan ? "\nPlan: " + plan : "") +
|
|
(message ? "\nNachricht: " + message : "");
|
|
|
|
var body = '{"sender":{"name":"checkflo","email":"hallo@checkflo.de"},' +
|
|
'"to":[{"email":"checkflo@motocamp.de"}],' +
|
|
'"subject":"' + subject + '",' +
|
|
'"textContent":"' + text.replace(/\n/g, "\\n") + '"}';
|
|
|
|
try {
|
|
$http.send({
|
|
url: "https://api.brevo.com/v3/smtp/email",
|
|
method: "POST",
|
|
headers: { "api-key": key, "Content-Type": "application/json" },
|
|
body: body
|
|
});
|
|
} catch(err) {
|
|
console.error("Brevo error: " + String(err));
|
|
}
|
|
}, "inquiries");
|