# Send email from a Supabase Edge Function

> Supabase has no built-in email product. Call Scribase Mail from a Supabase Edge Function (Deno) with a plain fetch, triggered from your client or a database webhook.

Source: https://scribase.com/mail/send-email-supabase-edge-function

Supabase ships Postgres, auth and storage, but no email product, so sending usually means adding a separate vendor. A Supabase Edge Function is a Deno runtime, and Scribase Mail is a plain REST API, so no SDK install is needed inside the function.

## Write the function

Deno's fetch is global, so the function needs no dependency, no import map and no cold-start SDK download.

_supabase/functions/send-email/index.ts_

```ts
// supabase/functions/send-email/index.ts
Deno.serve(async (req) => {
  const { to, subject, html } = await req.json();
  const response = await fetch('https://mail-api.scribase.com/emails', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${Deno.env.get('SCRIBASE_MAIL_KEY')}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      from: 'Acme <hello@mail.acme.com>',
      to,
      subject,
      html,
    }),
  });
  const data = await response.json();
  return Response.json(data, { status: response.status });
});
```

## Set the key and deploy

Store the Scribase Mail key as a function secret; it never reaches the client.

```sh
supabase functions deploy send-email
supabase secrets set SCRIBASE_MAIL_KEY=sk_live_...
```

## Call it from your app

Invoke the function with the Supabase client, or trigger it from a Postgres webhook on insert.

```ts
// Call it from your app with the Supabase client
const { data, error } = await supabase.functions.invoke('send-email', {
  body: { to: ['you@example.com'], subject: 'Hi', html: '<p>Hi</p>' },
});
```

## Before sending real mail

Add and verify a sending domain (POST /domains, publish the DKIM/SPF/DMARC records, then verify) or use an sk_test_ key while building.

_Scribase Mail plans (USD a month), from the live /billing/plans endpoint_

| Plan | Price | Emails a month | Daily cap |
| --- | --- | --- | --- |
| Free | $0 | 3,000 emails a month | 100 emails a day |
| Pro | $20 | 50,000 emails a month | No daily cap |
| Scale | $90 | 150,000 emails a month | No daily cap |

## FAQ

**Does this replace a Supabase feature?**

No. Supabase itself has no email-sending product; this is the function wiring for calling any email API, including Scribase Mail, from Supabase's own edge runtime.

**Can I run this on Scribase instead of Supabase?**

Yes. Scribase bundles Postgres, auth, storage and Mail in one account, so the equivalent function and the email API it calls can both live on Scribase with no second vendor.

**Do I need a verified domain to test the function?**

No. An sk_test_ key sends with no verified domain; every send is simulated and never delivered, so the function and its caller can be exercised end to end before DNS work.

## Related

- [Scribase Mail overview](https://scribase.com/mail)
- [Scribase Mail docs](https://scribase.com/mail/docs)
- [Migrate from Resend](https://scribase.com/mail/migrate-from-resend)
- [Resend alternative](https://scribase.com/resend-alternative)
- [Scribase vs Supabase](https://scribase.com/scribase-vs-supabase)
- [One backend](https://scribase.com/one-backend)