Edge Functions

Sending Emails


Sending emails from Edge Functions using the Resend API.

Prerequisites

To get the most out of this guide, you’ll need to:

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

1. Create Supabase function

Create a new function locally:

1
supabase functions new resend

Store the RESEND_API_KEY in your .env file.

2. Edit the handler function

Paste the following code into the index.ts file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const = ..('RESEND_API_KEY')const = async (: ): <> => { const = await ('https://api.resend.com/emails', { : 'POST', : { 'Content-Type': 'application/json', : `Bearer ${}`, }, : .({ : 'onboarding@resend.dev', : 'delivered@resend.dev', : 'hello world', : '<strong>it works!</strong>', }), }) const = await .() return new (.(), { : 200, : { 'Content-Type': 'application/json', }, })}.()

3. Deploy and send email

Run function locally:

1
2
supabase startsupabase functions serve --no-verify-jwt --env-file .env

Test it: http://localhost:54321/functions/v1/resend

Deploy function to Supabase:

1
supabase functions deploy resend --no-verify-jwt

Open the endpoint URL to send an email:

4. Try it yourself

Find the complete example on GitHub.