Skip to main content
Resend Docs

Search documentation

Type to search this documentation.

On this pageOverview

Send emails with Supabase Edge Functions

Before you start, you'll need:

Make sure you have the latest version of the Supabase CLI installed.

  1. Create Supabase function

    Create a new function locally:

    Bash
    supabase functions new resend
  2. Edit the handler function

    Paste the following code into the index.ts file:

    index.ts
    const RESEND_API_KEY = Deno.env.get('RESEND_API_KEY');
    
    const handler = async (_request: Request): Promise<Response> => {
      const res = await fetch('https://api.resend.com/emails', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': `Bearer ${RESEND_API_KEY}`,
        },
        body: JSON.stringify({
          from: 'Acme <onboarding@resend.dev>',
          to: ['delivered@resend.dev'],
          subject: 'hello world',
          html: '<strong>it works!</strong>',
        }),
      });
    
      const data = await res.json();
    
      return new Response(JSON.stringify(data), {
        status: 200,
        headers: {
          'Content-Type': 'application/json',
        },
      });
    };
    
    Deno.serve(handler);
  3. Deploy and send email

    Run function locally:

    Bash
    supabase functions start
    supabase functions serve resend --no-verify-jwt

    Deploy function to Supabase:

    Bash
    supabase functions deploy resend

    Open the endpoint URL to send an email:

    Supabase Edge Functions - Deploy Function

Supabase Edge Functions Example

See the full source code.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu