Edge Functions & Database Webhooks•Postgres & Backend as a Service

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-email
Setup Tutorial

Get Up and Running in 3 Easy Steps

01

Create a Supabase Edge Function

Run `supabase functions new send-email` in your terminal to scaffold a serverless TypeScript function powered by Deno.

02

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()`.

03

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.

supabase/functions/send-email/index.ts
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 });
  }
});
Why Developers Love It

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.

Got Questions?

Frequently Asked Questions about Supabase

Yes. In your Supabase Dashboard, navigate to Authentication > SMTP Settings. Enable Custom SMTP and enter: Host: `smtp.mailofly.com`, Port: `587`, Encryption: `TLS`, Username: `apikey`, and Password: your Mailofly API key. All verification links and password resets will immediately route through your verified custom domain.

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.