Send email with Supabase Edge Functions
A server-side call to the SendSend API from your Supabase Edge Functions app.
- Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
- Store the key as a secret: run `supabase secrets set SENDSEND_API_KEY=ss_live_...`, then deploy the function.
- Add this to
supabase/functions/send/index.ts:
Deno.serve(async (req) => {
const { to } = await req.json();
const res = await fetch('https://api.sendsend.email/v1/emails', {
method: 'POST',
headers: {
Authorization: `Bearer ${Deno.env.get('SENDSEND_API_KEY')}`,
'Content-Type': 'application/json',
'Idempotency-Key': crypto.randomUUID(),
},
body: JSON.stringify({ from: 'Acme <hello@mail.acme.com>', to: [to], subject: 'Hello from Supabase', html: '<p>It works!</p>' }),
});
return new Response(await res.text(), { status: res.status, headers: { 'Content-Type': 'application/json' } });
});Good to know
- A
202response means the message was queued, not delivered. See message states and webhooks. - Always send an Idempotency-Key, so a retry cannot send twice.
- Check the response status. Errors have one shape: see Errors.
- More options: attachments, scheduling, headers, templates and React Email.