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
Early Access

Building AI agents that send email?

Join the SadaSend early access waitlist to get scoped API keys, recipient allowlists, and Model Context Protocol (MCP) servers upon launch.

Rolling out in developer batches·No credit card needed
Social Hashtags & Share
#EmailAPI#DeveloperTools#Supabase#Postgres#Webhooks#Serverless
Tayyab MughalFounder & AI Chief

Building SadaSend — transactional email with an MCP server that has a ceiling. Writes about deliverability, email infrastructure, and what happens when you hand an autonomous agent a sending credential.

Keep reading