Skip to content
Writing
SupabasePostgresWebhooksServerless

Supabase Edge Functions & Email Webhooks: Realtime Database Triggers

Trigger instant welcome emails, invoice receipts, and password alerts when rows are inserted into your Supabase Postgres database.

Tayyab MughalFounder & AI Chief2 min read

Event-driven email architecture in Supabase

Instead of manually calling email endpoints across multiple frontend forms, Supabase Database Webhooks listen for INSERT events on auth.users or public.orders, immediately executing a Supabase Edge Function.

Supabase Edge Function (supabase/functions/send-email/index.ts)

Here is the Edge Function receiving the Postgres webhook payload and dispatching the email.

TYPESCRIPT
import "jsr:@supabase/functions-js/edge-runtime.d.ts";

interface WebhookRecord {
  type: 'INSERT';
  table: 'orders';
  record: { id: string; user_email: string; total_amount: number };
}

Deno.serve(async (req) => {
  const payload: WebhookRecord = await req.json();
  const { user_email, id, total_amount } = payload.record;

  const res = await fetch('https://api.sadasend.com/v1/emails', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${Deno.env.get('SADASEND_API_KEY')}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: user_email,
      subject: `Receipt for Order #${id}`,
      text: `Thank you for your purchase of ${(total_amount / 100).toFixed(2)}!`,
    }),
  });

  return new Response(JSON.stringify(await res.json()), { headers: { 'Content-Type': 'application/json' } });
});

Configuring the Webhook in Supabase Dashboard

  • Navigate to Database → Webhooks → Create a new webhook.
  • Target table: orders on INSERT events.
  • Webhook URL: https://<project-ref>.supabase.co/functions/v1/send-email
Free plan

Building AI agents that send email?

Scoped API keys, per-key recipient allowlists, approval mode and a hosted MCP server with ten tools — on the free plan, without a card.