From 5a26343ff25f9e4729f4eff2f086beae8b647003 Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Sat, 11 Jul 2026 13:49:16 +0000
Subject: [PATCH] Changes
Co-authored-by: wolfoftyreso-debug <250630591+wolfoftyreso-debug@users.noreply.github.com>
---
.../functions/send-outreach-email/index.ts | 87 +++++++++++++++++++
1 file changed, 87 insertions(+)
create mode 100644 supabase/functions/send-outreach-email/index.ts
diff --git a/supabase/functions/send-outreach-email/index.ts b/supabase/functions/send-outreach-email/index.ts
new file mode 100644
index 0000000..fd843d5
--- /dev/null
+++ b/supabase/functions/send-outreach-email/index.ts
@@ -0,0 +1,87 @@
+import { z } from "npm:zod@3.23.8";
+
+const corsHeaders = {
+ "Access-Control-Allow-Origin": "*",
+ "Access-Control-Allow-Headers":
+ "authorization, x-client-info, apikey, content-type",
+ "Access-Control-Allow-Methods": "POST, OPTIONS",
+};
+
+const GATEWAY_URL = "https://connector-gateway.lovable.dev/brevo";
+
+const BodySchema = z.object({
+ to_email: z.string().email(),
+ to_name: z.string().min(1).max(200),
+ subject: z.string().min(1).max(300),
+ body: z.string().min(1).max(10000),
+});
+
+Deno.serve(async (req) => {
+ if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });
+
+ try {
+ const LOVABLE_API_KEY = Deno.env.get("LOVABLE_API_KEY");
+ const BREVO_API_KEY = Deno.env.get("BREVO_API_KEY");
+ if (!LOVABLE_API_KEY || !BREVO_API_KEY) {
+ throw new Error("Email service not configured");
+ }
+
+ const parsed = BodySchema.safeParse(await req.json());
+ if (!parsed.success) {
+ return new Response(
+ JSON.stringify({ error: "Ogiltiga fält", details: parsed.error.flatten().fieldErrors }),
+ { status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } },
+ );
+ }
+ const { to_email, to_name, subject, body } = parsed.data;
+
+ const senderEmail = Deno.env.get("BREVO_SENDER_EMAIL") ?? "konditorivaror@gmail.com";
+ const senderName = "Tiffany – Lennart Svenssons Konditorivaror";
+
+ // Konvertera radbrytningar till
för HTML
+ const htmlBody = `
+
${p.replace(/\n/g, "
")}