Prompt

How to send email from Supabase Edge Functions

Technology / Api platforms1 observationLast seen Aug 13, 2026

Latest observation

Aug 13, 2026 · OpenAI APIWeb search: off

To send email from Supabase Edge Functions, you typically use an external email provider API such as Resend, SendGrid, Mailgun, or Postmark. Edge Functions run on the edge and don’t include a built-in SMTP client, so calling an HTTP email API is the most reliable approach.

Recommended approach: use an email API

1) Create an Edge Function

supabase functions new send-email

2) Add your email provider API key as a secret

Example with Resend:

supabase secrets set RESEND_API_KEY=your_api_key

3) Write the function

Example using Resend:

// supabase/functions/send-email/index.ts
import { serve } from "https://deno.land/std/http/server.ts";

serve(async (req) => {
  try {
    const { to, subject, html } = await req.json();

    const resendRes = await fetch("https://api.resend.com/emails", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${Deno.env.get("RESEND_API_KEY")}`,
      },
      body: JSON.stringify({
        from: "Your App <noreply@yourdomain.com>",
        to,
        subject,
        html,
      }),
    });

    if (!resendRes.ok) {
      const error = await resendRes.text();
      return new Response(JSON.stringify({ error }), {
        status: 500,
        headers: { "Content-Type": "application/json" },
      });
    }

    const data = await resendRes.json();

    return new Response(JSON.stringify({ success: true, data }), {
      headers: { "Content-Type": "application/json" },
    });
  } catch (err) {
    return new Response(JSON.stringify({ error: String(err) }), {
      status: 500,
      headers: { "Content-Type": "application/json" },
    });
  }
});

4) Deploy the function

supabase functions deploy send-email

5) Call it from your app

const res = await fetch("https://<project-ref>.functions.supabase.co/send-email", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: `Bearer <user-access-token>`,
  },
  body: JSON.stringify({
    to: "user@example.com",
    subject: "Welcome!",
    html: "<h1>Hello</h1><p>Thanks for signing up.</p>",
  }),
});

const data = await res.json();
console.log(data);

Important notes

Use an email service, not raw SMTP

Supabase Edge Functions are best with HTTP-based APIs. SMTP libraries can be problematic in Edge/Deno environments.

Keep API keys in secrets

Never hardcode keys in your function code. Use:

supabase secrets set NAME=value

Verify your sender domain

Most providers require you to verify your sending domain before you can send successfully.

Secure the function

If the function should only be called by authenticated users, verify the JWT or use Supabase auth checks.


Alternative providers

The pattern is the same for:

  • SendGrid: POST to /v3/mail/send
  • Mailgun: POST to their messages endpoint
  • Postmark: POST to /email

If you want, I can also give you:

  1. a Supabase Edge Function example with Resend + JWT auth, or
  2. a SendGrid/Postmark version, or
  3. a full email template helper setup.

Observation history

Unlock observation history

Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.