How to Send Emails with Supabase & Mailofly
Trigger transactional emails from Supabase Edge Functions, Postgres database webhooks, or authentication flows with sub-100ms API latency.
supabase functions new send-emailGet Up and Running in 3 Easy Steps
Create a Supabase Edge Function
Run `supabase functions new send-email` in your terminal to scaffold a serverless TypeScript function powered by Deno.
Set your Mailofly API Secret
Run `supabase secrets set MAILOFLY_API_KEY=mf_live_...` to make your API key available securely inside `Deno.env.get()`.
Call Mailofly REST API or SMTP
Deploy the function or connect Mailofly as your custom SMTP provider in the Supabase Dashboard under Project Settings > Authentication > SMTP.
Production-Ready Code Example
Copy and paste into your project. Fully typed and tested.
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
Deno.serve(async (req) => {
if (req.method !== "POST") {
return new Response("Method Not Allowed", { status: 405 });
}
try {
const { email, subject, text, html } = await req.json();
const apiKey = Deno.env.get("MAILOFLY_API_KEY");
const res = await fetch("https://api.mailofly.com/v1/emails", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
from: "Acme App <notifications@yourdomain.com>",
to: [email],
subject: subject || "Notification from Acme",
html: html || `<p>${text}</p>`,
}),
});
const data = await res.json();
return new Response(JSON.stringify(data), {
headers: { "Content-Type": "application/json" },
status: res.ok ? 200 : 400,
});
} catch (err: any) {
return new Response(JSON.stringify({ error: err.message }), { status: 500 });
}
});Engineered for Supabase
Postgres Webhook Triggers
Trigger emails automatically when new rows are inserted into your `users`, `orders`, or `comments` tables.
Native Deno Edge Runtime
Zero third-party dependencies required. Standard `fetch()` calls send emails to Mailofly in under 100ms.
Custom Auth SMTP Option
Replace Supabase's default rate-limited auth emails with Mailofly SMTP (`smtp.mailofly.com`:587) for branded domain delivery.
Explore Mailofly Infrastructure Capabilities
Build resilient, high-deliverability email systems with our core developer tools.
Frequently Asked Questions about Supabase
Start Sending from Supabase in Minutes
3,000 free emails every month. Copy your API key, run the code snippet, and watch your delivery logs in real time.