Keplars

Supabase Integration

Send emails using Keplars with Supabase Edge Functions

Deploy Keplars as a Supabase Edge Function to send transactional and scheduled emails from your Supabase projects.

Overview

This integration provides a ready-to-use Supabase Edge Function that connects to Keplars email service. Built with Deno and TypeScript, it seamlessly integrates with your existing Supabase project.

GitHub Repository: github.com/KeplarsHQ/supabase-example

Features

  • Template-based emails - Use pre-designed templates with dynamic variables
  • Raw HTML/Text emails - Send custom HTML or plain text without templates
  • Scheduled emails - Schedule emails with timezone support
  • Instant delivery - 0-5 second delivery for critical emails
  • TypeScript - Full type safety with Deno
  • JWT verification - Optional authentication with Supabase Auth

Prerequisites

Before starting, you'll need:

Quick Start

1. Clone the Example

git clone https://github.com/KeplarsHQ/supabase-example.git
cd supabase-example

2. Configure API Key

Create a .env.local file in the supabase folder:

cd supabase
cp .env.local.example .env.local

Add your Keplars API key:

KEPLARS_API_KEY=kms_your_actual_api_key_here

3. Start Local Development

supabase start

The function will be available at:

http://127.0.0.1:54321/functions/v1/keplars-email-function

4. Test the Function

Send a test email:

curl --request POST 'http://127.0.0.1:54321/functions/v1/keplars-email-function' \
  --header 'Content-Type: application/json' \
  --data @test-text-email.json

Deployment

Deploy to Supabase Cloud

  1. Link your Supabase project:
supabase link --project-ref your-project-ref
  1. Set your API key as a secret:
supabase secrets set KEPLARS_API_KEY=kms_your_actual_api_key_here
  1. Deploy the function:
supabase functions deploy keplars-email-function

Your function will be live at:

https://your-project-ref.supabase.co/functions/v1/keplars-email-function

Usage Examples

Template-Based Email

{
  "to": ["[email protected]"],
  "template_id": "your_template_id",
  "params": {
    "user_name": "John Doe",
    "verification_code": "123456"
  },
  "delivery_type": "instant"
}

Plain Text Email

{
  "to": ["[email protected]"],
  "subject": "Welcome!",
  "body": "Thanks for signing up. We're excited to have you.",
  "delivery_type": "instant"
}

HTML Email

{
  "to": ["[email protected]"],
  "subject": "Welcome!",
  "html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
  "is_html": true,
  "delivery_type": "instant"
}

Scheduled Email

{
  "to": ["[email protected]"],
  "subject": "Weekly Newsletter",
  "html": "<h1>This Week's Updates</h1>",
  "scheduled_at": "2026-01-25T10:00:00",
  "timezone": "America/New_York"
}

Client Integration

JavaScript/TypeScript

import { createClient } from '@supabase/supabase-js'

const supabase = createClient(
  'https://your-project-ref.supabase.co',
  'your-anon-key'
)

// Send an email
const { data, error } = await supabase.functions.invoke('keplars-email-function', {
  body: {
    to: ['[email protected]'],
    template_id: 'your_template_id',
    params: {
      user_name: 'John',
      verification_code': '123456'
    },
    delivery_type: 'instant'
  }
})

if (error) {
  console.error('Failed to send email:', error)
} else {
  console.log('Email sent!', data)
}

React Example

import { useSupabaseClient } from '@supabase/auth-helpers-react'

function WelcomeEmail() {
  const supabase = useSupabaseClient()

  const sendWelcome = async (email: string, name: string) => {
    await supabase.functions.invoke('keplars-email-function', {
      body: {
        to: [email],
        template_id: 'your_welcome_template_id',
        params: { user_name: name }
      }
    })
  }

  return <button onClick={() => sendWelcome('[email protected]', 'Jane')}>
    Send Welcome Email
  </button>
}

Next.js API Route

// app/api/send-email/route.ts
import { createClient } from '@supabase/supabase-js'

export async function POST(request: Request) {
  const { email, name } = await request.json()

  const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.SUPABASE_SERVICE_ROLE_KEY!
  )

  const { data, error } = await supabase.functions.invoke('keplars-email-function', {
    body: {
      to: [email],
      template_id: process.env.KEPLARS_TEMPLATE_ID,
      params: { user_name: name }
    }
  })

  return Response.json({ success: !error, data })
}

Security

Enable JWT Verification

For production, enable JWT verification in supabase/config.toml:

[functions.keplars-email-function]
verify_jwt = true

This requires all requests to include a valid Supabase auth token.

Environment Variables

  • Keep your .env.local file secure (never commit it)
  • Use supabase secrets for production API keys
  • Use different API keys for development and production

API Reference

Request Fields

Required:

  • to - Array of email addresses
  • For template emails: template_id
  • For raw emails: subject + either body or html

Optional:

  • params - Template variables (template emails only)
  • is_html - Set to true for HTML content
  • delivery_type - Either "instant" or "queue"
  • scheduled_at - ISO 8601 timestamp for scheduled emails
  • timezone - IANA timezone (e.g., "America/New_York")
  • from - Sender email
  • fromName - Sender name

Response Format

Success:

{
  "id": "msg_...",
  "object": "email",
  "status": "queued",
  "from": "[email protected]",
  "to": ["[email protected]"],
  "created_at": "2026-01-22T22:14:04.470Z"
}

Error:

{
  "success": false,
  "error": "Error message",
  "code": "ERROR_CODE"
}

Troubleshooting

Function not found

Make sure you've deployed the function:

supabase functions deploy keplars-email-function

API key not configured

Ensure your API key is set:

# Local
echo "KEPLARS_API_KEY=kms_..." >> supabase/.env.local

# Production
supabase secrets set KEPLARS_API_KEY=kms_...

Email not arriving

  • Check your spam folder
  • Verify template exists in Keplars dashboard
  • Ensure email provider is connected in Keplars
  • Check Supabase function logs: supabase functions log keplars-email-function

Resources

Support

Need help? Reach out:

On this page