Quick setup examples
Supabase Edge Functions
Send your first email from a Supabase Edge Function by calling the SendPing API with fetch.
Send your first email from a Supabase Edge Function by calling the SendPing REST API. The sendping SDK targets Node.js/npm — Edge Functions run on Deno, which has a global fetch, so you POST JSON to https://www.sendping.co/api/emails directly.
Prerequisites
Before you start, you will need:
- A SendPing API key.
- A verified domain to send from.
- The Supabase CLI installed.
1. Create a Supabase function
Create a new function locally.
supabase functions new sendping2. Set your API key as a secret
Store your key as a function secret so it is read from the environment, not hardcoded.
supabase secrets set SENDPING_API_KEY=mb_xxxxxxxxx3. Edit the handler function
Paste the following code into the index.ts file.
index.ts
const SENDPING_API_KEY = Deno.env.get('SENDPING_API_KEY');
const handler = async (_request: Request): Promise<Response> => {
const res = await fetch('https://www.sendping.co/api/emails', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${SENDPING_API_KEY}`,
},
body: JSON.stringify({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@test.sendping.co'],
subject: 'hello world',
html: '<strong>it works!</strong>',
}),
});
const data = await res.json();
return new Response(JSON.stringify(data), {
status: res.ok ? 200 : res.status,
headers: { 'Content-Type': 'application/json' },
});
};
Deno.serve(handler);4. Deploy and send email
Run the function locally, then deploy it to Supabase and open the endpoint URL to send an email.
supabase functions serve sendping --no-verify-jwt
supabase functions deploy sendpingSee the full set of body fields in the Send an email reference.