Overview
This guide shows you how to integrate AutoSend with Supabase Edge Functions to send emails for authentication, notifications, and other transactional use cases. Edge Functions run at the edge, close to your users, making them perfect for handling email operations with low latency.Prerequisites
Before you begin, make sure you have:- An AutoSend account with an API key
- A Supabase project
- Supabase CLI installed (v1.0 or later)
- Node.js 18+ installed locally
Quickstart
1
Create a Supabase Edge Function
Initialize your Supabase project and create a new Edge Function:This creates a new function in
supabase/functions/autosend/index.ts.2
Install Dependencies
Edge Functions support importing from standard URLs. No package installation needed!
3
Write the Edge Function
Replace the content of
supabase/functions/autosend/index.ts with:4
Create Shared CORS Configuration
Create a file at
supabase/functions/_shared/cors.ts:5
New Step
Create a For production, set secrets using the Supabase CLI:
.env file in your project root (for local development):6
Run Locally
Test your function locally before deploying:The function will be available at:
http://localhost:54321/functions/v1/autosend7
Test Your Function
Send a test request using cURL:
8
Deploy to Production
Once tested, deploy your function:Your function will be available at:
Usage Examples
Send a Simple Email
Send a Simple Email
Send Using AutoSend Template
Send Using AutoSend Template
Send from React/Next.js
Send from React/Next.js
Integration with Supabase Auth
You can use AutoSend to send custom authentication emails by integrating with Supabase Auth Hooks.1
Create Auth Hook Function
2
Implement Auth Hook Handler
3
Configure Auth Hook in Supabase
- Go to Authentication > Hooks in your Supabase dashboard
- Enable the “Send Email” hook
-
Set the hook URL to your deployed function:
- Configure the secret (optional but recommended)
Error Handling
Implement robust error handling for production:Best Practices
Environment Variables
Environment Variables
Always use environment variables for sensitive data:
Validate Email Addresses
Validate Email Addresses
Validate email formats before sending:
Implement Rate Limiting
Implement Rate Limiting
Protect your function from abuse:
Use Verified Domains
Use Verified Domains
Always send from verified domains in AutoSend to ensure deliverability.
Learn how to verify domains →
Learn how to verify domains →