Lovable and Supabase Edge Functions
Apps built on Lovable run on Supabase Edge Functions — Deno, serverless. Use the HTTP API there, not SMTP: SMTP needs a connection held open, which is the one thing a function that may be frozen between requests cannot do.
The function
Deno.serve(async (req) => {
const { to, subject, html } = await req.json();
const response = await fetch("https://digitalpigeon.golux.tech/v1/emails", {
method: "POST",
headers: {
Authorization: `Bearer ${Deno.env.get("DIGITALPIGEON_API_KEY")}`,
"Content-Type": "application/json",
// Keeps a retried invocation from sending twice.
"Idempotency-Key": `${subject}-${to}`,
},
body: JSON.stringify({
from: "Prodavnica <hello@mail.prodavnica.rs>",
to: [to],
subject,
html,
text: html.replace(/<[^>]+>/g, " "),
}),
});
if (!response.ok) {
return new Response(await response.text(), { status: response.status });
}
return new Response(await response.text(), {
headers: { "Content-Type": "application/json" },
});
});
supabase secrets set DIGITALPIGEON_API_KEY=dp_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
If you are asking Lovable to write it
Assistants know the Resend shape by heart, so the quickest route is to let it write Resend code and then change two things. Ask for exactly that:
“Send the email with a plain
fetch in the Resend request format, but post to
https://digitalpigeon.golux.tech/v1/emails and read the key from DIGITALPIGEON_API_KEY.
Do not install the Resend SDK.”
The SDK is worth avoiding because it pins its own host, so it cannot be pointed here.
Two things that will bite otherwise
-
The from address must be on a domain you verified here. Sending as
onboarding@resend.devor any address you do not control is refused — that refusal is the reason this service cannot be used to send as someone else. - Send an idempotency key. Edge functions get retried on timeouts, and without one a retry means your user gets the same email twice.