Quick setup examples
Supabase Edge Functions
Send your first email from a Supabase Edge Function by calling the MailBlastr API with fetch.
Send your first email from a Supabase Edge Function by calling the MailBlastr REST API. The mailblastr SDK targets Node.js/npm — Edge Functions run on Deno, which has a global fetch, so you POST JSON to https://api.mailblastr.com/emails directly.
Prerequisites
Before you start, you will need:
- A MailBlastr 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 mailblastr2. 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 MAILBLASTR_API_KEY=mb_xxxxxxxxx3. Edit the handler function
Paste the following code into the index.ts file.
index.ts
const MAILBLASTR_API_KEY = Deno.env.get('MAILBLASTR_API_KEY');
const handler = async (_request: Request): Promise<Response> => {
const res = await fetch('https://api.mailblastr.com/emails', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${MAILBLASTR_API_KEY}`,
},
body: JSON.stringify({
from: 'Acme <onboarding@yourdomain.com>',
to: ['delivered@example.com'],
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 mailblastr --no-verify-jwt
supabase functions deploy mailblastrSee the full set of body fields in the Send an email reference.