Supabase Setup
Mailpipe uses Supabase as your email database. This guide walks you through creating a Supabase project and connecting it to Mailpipe.
Prerequisites
- A Supabase account (free tier works great for getting started)
- A Mailpipe account
Step 1: Create a Supabase Project
If you don't already have a Supabase project, create one at supabase.com. Choose a region close to your users for best performance.
Important: Make sure to save your database password during project creation. You'll need it later.
Step 2: Get Your Connection Credentials
In your Supabase dashboard, navigate to Project Settings -> API to find your credentials:
- Project URL: Your unique Supabase project URL
- anon/public key: Used for client-side operations
- service_role key: Used for server-side operations (keep this secret!)
Step 3: Connect to Mailpipe
In your Mailpipe dashboard, go to Settings -> Database and enter your Supabase credentials:
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=eyJhbGci...
SUPABASE_SERVICE_ROLE_KEY=eyJhbGci...Step 4: Run Database Migrations
Mailpipe will automatically create the required tables when you first connect. The following tables will be created:
-- Core tables created by Mailpipe
CREATE TABLE emails (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
mailbox_id UUID REFERENCES mailboxes(id),
from_address TEXT NOT NULL,
to_address TEXT NOT NULL,
subject TEXT,
text_body TEXT,
html_body TEXT,
headers JSONB,
received_at TIMESTAMPTZ DEFAULT NOW(),
read BOOLEAN DEFAULT FALSE,
starred BOOLEAN DEFAULT FALSE,
labels TEXT[]
);
CREATE TABLE mailboxes (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
address TEXT UNIQUE NOT NULL,
domain_id UUID REFERENCES domains(id),
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE routing_rules (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
priority INTEGER DEFAULT 0,
conditions JSONB NOT NULL,
actions JSONB NOT NULL,
enabled BOOLEAN DEFAULT TRUE
);Step 5: Enable Row Level Security (RLS)
For production use, we strongly recommend enabling Row Level Security. Mailpipe creates default RLS policies that ensure users can only access their own data:
-- Enable RLS on all tables
ALTER TABLE emails ENABLE ROW LEVEL SECURITY;
ALTER TABLE mailboxes ENABLE ROW LEVEL SECURITY;
ALTER TABLE routing_rules ENABLE ROW LEVEL SECURITY;
-- Example policy: Users can only see emails from their mailboxes
CREATE POLICY "Users can view own emails" ON emails
FOR SELECT
USING (
mailbox_id IN (
SELECT id FROM mailboxes
WHERE user_id = auth.uid()
)
);Step 6: Enable Real-Time (Optional)
To get instant email notifications and live updates in the Mailpipe UI, enable real-time on the emails table:
-- In Supabase Dashboard: Database > Replication
-- Or via SQL:
ALTER PUBLICATION supabase_realtime ADD TABLE emails;Troubleshooting
Connection Failed
If you're having trouble connecting, verify that:
- Your project URL is correct (no trailing slash)
- You're using the correct API keys
- Your Supabase project is not paused
Migration Errors
If migrations fail, check that your service role key has the necessary permissions. The service role key should have full access to create tables and policies.
Next Steps
Now that your database is set up, configure your email provider to start receiving emails.