# Supabase Custom SMTP & Transactional Email

> By default, Supabase Cloud projects restrict built-in auth emails to 2 per hour, causing 429 Too Many Requests errors during launch spikes. SadaSend provides instant, high-deliverability custom SMTP credentials and a type-safe REST API for Supabase Edge Functions, featuring pre-flight validation and 6,000 free emails a month.

## SMTP Configuration Parameters

| Supabase Setting Field | Value | Description |
| --- | --- | --- |
| Enable Custom SMTP | `Toggle ON` | Activates external transactional email routing in your Supabase Auth dashboard. |
| Sender Email | `auth@yourdomain.com` | The verified from address associated with your SadaSend domain. |
| Sender Name | `Your App Name` | Human-readable sender name displayed in user inboxes. |
| SMTP Host | `smtp.sadasend.com` | SadaSend global Anycast SMTP relay gateway. |
| SMTP Port | `587` | Standard submission port using explicit STARTTLS encryption (RFC 3207). |
| SMTP User | `sadasend` | Standard authentication username for all SadaSend SMTP connections. |
| SMTP Password | `your_sadasend_api_key` | Your production or test API key generated in the SadaSend dashboard. |

## Supabase Edge Function (Deno)

```typescript
// Supabase Edge Function: supabase/functions/send-email/index.ts
// Direct native fetch dispatch to SadaSend REST API (low latency)
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';

serve(async (req) => {
  if (req.method !== 'POST') {
    return new Response('Method Not Allowed', { status: 405 });
  }

  const { to, subject, html } = await req.json();

  const response = await fetch('https://api.sadasend.com/v1/emails', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${Deno.env.get('SADASEND_API_KEY')}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      from: 'alerts@yourdomain.com',
      to,
      subject,
      html,
    }),
  });

  const result = await response.json();
  return new Response(JSON.stringify(result), {
    headers: { 'Content-Type': 'application/json' },
    status: response.status,
  });
});
```

## Next.js 15 Server Action (Supabase Auth)

```typescript
// Next.js 15 Server Action: app/actions/auth.ts
// Initiates Supabase magic link with SadaSend custom SMTP delivery
'use server';

import { createClient } from '@/lib/supabase/server';

export async function signInWithMagicLink(formData: FormData) {
  const email = formData.get('email') as string;
  const supabase = await createClient();

  const { error } = await supabase.auth.signInWithOtp({
    email,
    options: {
      emailRedirectTo: `${process.env.NEXT_PUBLIC_SITE_URL}/auth/callback`,
    },
  });

  if (error) {
    throw new Error(error.message); // No more 429 Too Many Requests!
  }

  return { success: true };
}
```

## Local Development (supabase/config.toml)

```toml
# Supabase Local Development: supabase/config.toml
# Point local Docker containers to SadaSend staging keys with allowlists

[auth.email]
enable_signup = true
double_confirm_changes = true
enable_confirmations = true

[auth.email.smtp]
enabled = true
host = "smtp.sadasend.com"
port = 587
user = "sadasend"
pass = "env(SADASEND_STAGING_KEY)"
admin_email = "admin@yourdomain.com"
sender_name = "Local Dev Auth"
```

## Frequently Asked Questions

### Why does Supabase return error 429: "Email rate limit exceeded"?

By default, Supabase Cloud projects share an internal built-in email service with a restrictive quota of 2 emails per hour on the Free tier and approximately 30 emails per hour on Pro. When multiple users sign up or request magic links within a short window, Supabase throws an HTTP 429 error. Connecting SadaSend custom SMTP immediately removes this restriction, allowing unthrottled transactional delivery.

### How long does it take to connect SadaSend custom SMTP to Supabase?

Under 3 minutes. In your Supabase Dashboard, navigate to Project Settings -> Authentication -> SMTP Settings, toggle Enable Custom SMTP to ON, and enter host smtp.sadasend.com on port 587 with your SadaSend API key as the password.

### Can I use SadaSend with Supabase Edge Functions?

Yes. In addition to standard Supabase Auth SMTP, you can dispatch transactional emails directly from Deno-based Supabase Edge Functions using native fetch to https://api.sadasend.com/v1/emails. This enables programmatic notifications for Stripe webhooks, database triggers, and AI agent events.

### Does SadaSend protect local Supabase Docker development from leaking emails?

Yes. With SadaSend’s per-key recipient allowlists, you can issue an API key dedicated to local development (in supabase/config.toml) that is strictly constrained to only send to your team’s domain (e.g. *@yourcompany.com). Any test emails addressed to real customer addresses are safely rejected at the gateway.

### How much does it cost to use SadaSend with Supabase?

SadaSend offers 6,000 free transactional emails with no expiration date and no credit card required. When your Supabase application scales, paid plans start at $12/month for 15,000 emails, $19/month for 75,000 emails, and $79/month for 250,000 emails with clean, verified IP pools included.
