Skip to content
NewA free test that shows whether your emails will reach the inbox.
Get started
Works todayDeno handler checked; hosted setup not exercised, 9 min read

Lovable email integration: send and receive replies

A protected Supabase Edge Function sends a fixed welcome email to the signed-in user through Runearc. Keep the API key in server secrets, verify your domain and add receiving only when your app needs replies.

Ask Lovable
Add a protected Supabase Edge Function that sends email through Runearc.

Choose native email or an external API

To send email from a Lovable app, you can use Lovable's native email feature or call an external API from your server. For a project connected to your own Supabase account, this guide adds a protected Edge Function that sends through Runearc. The function keeps your key in server secrets and emails only the signed-in user's confirmed address. Add receiving when your app needs to read replies.

Lovable now offers branded transactional emails on paid plans, including domain setup and templates. Its documentation lists 50,000 transactional emails per workspace per month included, with hourly limits and paid usage beyond the allowance. You do not have to create a Resend or Runearc account to use that native feature. Source [1], checked November 26, 2026.

Swipe sideways to see every column.

Your projectStart hereWhy
Native Lovable app emailsMore → EmailsManaged transactional emails within Lovable
Own Supabase project + external providerA protected Edge FunctionControl the provider and reuse sending with a receiving inbox
Supabase Auth emailsCustom SMTP in Supabase AuthAuth creates the tokens; the email provider transports the messages
The code below is for your own connected Supabase project. Built-in Lovable backend settings and deployment paths differ.

These choices do not change your app's hosting domain. Sending email requires its own verified sender domain. Native Lovable Auth is also distinct from authentication in your own Supabase project; do not apply Supabase dashboard instructions to a backend account you do not control.

Connect Supabase and store secrets

Use the Supabase project that belongs to this app.

  1. 1

    Connect your Supabase project

    Use Lovable's Supabase integration and confirm the selected project. Lovable can deploy Edge Functions there; source [2] documents the connection.
  2. 2

    Verify your Runearc sender domain

    Follow domain setup, publish the supplied records and wait for verified status. Create a sending inbox such as support@yourdomain.com. Keep employees' existing MX records; use a receiving subdomain if needed.
  3. 3

    Store server secrets

    In the Supabase project's Edge Function secrets, add RUNEARC_API_KEY, RUNEARC_INBOX_ID and APP_ORIGIN. The origin is the exact HTTPS scheme and host of your app. The runtime supplies SUPABASE_URL and SUPABASE_ANON_KEY.
  4. 4

    Keep authentication enabled

    Set verify_jwt = true for this function. The code also asks Supabase Auth for the current user. Never turn this into a public endpoint that accepts arbitrary recipients or email content.

Enter the Runearc key through the project's secret input, not in the Lovable chat or a committed file. The key is read only on the server. A VITE_RUNEARC_API_KEY value would expose it in a browser build. For the available sending and inbox scopes, read API keys.

A protected Edge Function

A fixed template to the signed-in user's confirmed address; the browser chooses neither content nor recipient.

Put this file at supabase/functions/send-welcome/index.ts. It verifies the user through the Auth server, checks the origin for browser requests, and calls Runearc's inbox send endpoint. CORS limits browser access; the JWT check is what authenticates the caller. A publishable key alone is not a user session.

// supabase/functions/send-welcome/index.ts
const origin = Deno.env.get("APP_ORIGIN")!; // e.g. https://app.example.com
const cors = {
  "Access-Control-Allow-Origin": origin,
  "Access-Control-Allow-Headers": "authorization, apikey, content-type, x-client-info",
  "Access-Control-Allow-Methods": "POST, OPTIONS",
  "Vary": "Origin",
};
const json = (status: number, data: unknown) => Response.json(data, { status, headers: cors });

export async function handler(req: Request): Promise<Response> {
  if (req.headers.get("Origin") && req.headers.get("Origin") !== origin)
    return json(403, { error: "Origin not allowed" });
  if (req.method === "OPTIONS") return new Response(null, { status: 204, headers: cors });
  if (req.method !== "POST") return json(405, { error: "Use POST" });
  const authorization = req.headers.get("Authorization") ?? "";
  if (!authorization.startsWith("Bearer ")) return json(401, { error: "Sign in first" });
  try {
    // Ask Supabase Auth to validate the token; never just decode its claims.
    const auth = await fetch(`${Deno.env.get("SUPABASE_URL")}/auth/v1/user`, {
      headers: { Authorization: authorization, apikey: Deno.env.get("SUPABASE_ANON_KEY")! },
      signal: AbortSignal.timeout(5000),
    });
    if (!auth.ok) return json(401, { error: "Sign in again" });
    const user = await auth.json();
    if (!user.id || !user.email || !user.email_confirmed_at)
      return json(403, { error: "Confirm your email first" });
    // The client supplies neither recipient nor subject/body. One fixed template
    // to this user's confirmed address, at most once per UTC day (24h key TTL).
    const day = new Date().toISOString().slice(0, 10);
    const base = Deno.env.get("RUNEARC_API_URL") ?? "https://api.runearc.com/v1";
    const inbox = Deno.env.get("RUNEARC_INBOX_ID")!;
    const result = await fetch(`${base}/inboxes/${encodeURIComponent(inbox)}/messages`, {
      method: "POST", signal: AbortSignal.timeout(5000),
      headers: { Authorization: `Bearer ${Deno.env.get("RUNEARC_API_KEY")}`,
        "Content-Type": "application/json", "Idempotency-Key": `welcome:${user.id}:${day}` },
      body: JSON.stringify({ to: user.email, subject: "Welcome to Acme",
        text: "Thanks for joining Acme. Reply to this email if you need help." }),
    });
    if (!result.ok) return json(502, { error: "Email could not be queued; retry later" });
    return json(200, { queued: true }); // Accepted, not proof of final delivery.
  } catch { return json(503, { error: "Temporarily unavailable" }); }
}

if (import.meta.main) Deno.serve(handler);

Deploy with Lovable's connected Supabase workflow, or supabase functions deploy send-welcome against the intended linked project. Use the app's authenticated Supabase client to invoke it. The SDK supplies the session token; a missing, expired or invalid token must fail. Sources [3–4] describe the authorization contract.

Runearc remembers idempotency keys for 24 hours. This example reuses one key per user per UTC day with a fixed body. Two calls on the same day return the same stored send; a new day permits another. This is duplicate protection for this template, not a complete public-mail abuse policy. Add durable per-account quotas, signup controls and an application outbox for a real onboarding workflow.

A prompt for Lovable

Paste this instruction into the project chat, then provide secret values only through the secure input. Review the generated function against the code above, particularly the authenticated recipient and fixed template.

This Lovable project uses my own connected Supabase project.
Add a send-welcome Edge Function using the code in this guide.
Keep RUNEARC_API_KEY and RUNEARC_INBOX_ID in Supabase secrets, never in VITE_ variables.
Keep JWT verification enabled and verify the current user with Supabase Auth.
Send only the fixed welcome template to that user's confirmed email address.
Do not accept to, subject or body from the browser.
Use a stable per-user, per-UTC-day Idempotency-Key, not a fresh random key per click.
Set APP_ORIGIN to this app's actual HTTPS origin, and handle CORS preflight.
Call it through supabase.functions.invoke after sign-in, with loading/error states.
Show "Email queued" after success; do not claim it was delivered.
Add account-level abuse controls before making it available publicly.

Disable the button while the request runs, surface a useful error on failure, and show “Email queued” on success. The API's accepted response does not establish that a recipient server has delivered it. Use delivery events when the app needs that later status.

Authentication emails use SMTP

This welcome function runs after a user has signed in and confirmed their email. It does not generate password resets, confirmation tokens or magic links. In your own Supabase project, configure custom SMTP so Supabase Auth creates those messages and sends them through Runearc. Source [5] describes the separate setting.

Enable custom SMTP   on
Host                 smtp.runearc.com
Port                 465 (TLS), or 587 (STARTTLS)
Username             runearc
Password             a Runearc key with sending access
Sender email         support@your-verified-domain.com
Sender name          Your app

Keep the sender on your verified domain and the password in the SMTP settings. Follow the Supabase custom SMTP guide for full setup and testing; the Supabase SMTP provider comparison explains alternatives. For native Lovable Auth on its built-in backend, start with Lovable's Emails settings rather than these separate-project SMTP steps.

Receive replies

The welcome message is sent from the inbox you selected, so users can reply to it. To bring those replies into your application, register a message.received webhook, verify its raw-body signature and timestamp, fetch the stored message, and save it with a unique message id. Match a known conversation and participant before attaching it to a customer account.

A webhook from Runearc authenticates with its webhook signature, not a Supabase user session. Give receiving its own endpoint and authentication configuration; do not disable JWT checks on send-welcome just to accept webhooks there. The complete SaaS replies guide implements signature verification, duplicate handling, sender checks and review of automatic replies.

Runearc's stored inboxes let you refetch mail after a handler failure. The thread model follows Message-ID references. Rendering untrusted HTML, handling attachments and authorizing each tenant's access remain application responsibilities.

Verify the implementation

On November 26, 2026 we checked this TypeScript with Deno 2.9.6 and ran the handler under Deno against an isolated local Runearc API. Missing and invalid tokens were rejected; a different origin was rejected; CORS preflight succeeded. A confirmed-user Auth response fixture permitted one real API send, and repeating the request produced one stored message through the stable idempotency key.

The authentication success response came from a local contract fixture, not a hosted Supabase session. We did not run the Lovable editor, deploy a hosted Edge Function, or deliver mail externally. The local outbound relay was disabled, and the throwaway stack was removed. Verify the actual Supabase session, configured origin, domain status and received email in your deployed project before making the feature available to users.

Runearc's free plan has 3,000 sent recipients per month, three inboxes and three custom domains, with no card. External sends carry a Sent via Runearc footer, new workspaces start at 100 recipients per day for seven days, and an unverified workspace remains in the sending sandbox. Read sending limits before testing with a customer address.

If it fails

401 or Sign in again
Invoke through a signed-in Supabase client, with a user access token in Authorization. Keep JWT verification on. An anon or publishable key is not a user token.
Origin not allowed or CORS error
Set APP_ORIGIN to the exact app origin, including https and any subdomain. Check preflight and the response headers. Do not use an arbitrary request origin as the allow list.
Confirm your email first
Complete confirmation for this Supabase user. The function requires email_confirmed_at and does not send to an unverified address supplied by the client.
Email could not be queued
Check server-side Runearc domain status, key scope, inbox id and sending limits. Keep provider credentials and raw errors out of browser responses.
Only one welcome email appears
Repeated calls on the same UTC day intentionally reuse an idempotency key. For a different business event, define a separate durable event id; do not replace duplicate protection with a random key on every retry.

Questions

Does every Lovable app need an external email provider?

No. Lovable has its own branded transactional email feature on paid plans. Use an external API when you need a separate email account, receiving inboxes, or an integration your backend controls. This guide uses your own connected Supabase project.

Can I put the Runearc key in a VITE_ variable?

No. VITE_ values can become part of the browser bundle. Put the key in Supabase secrets and call Runearc only inside the Edge Function.

Can this function send password resets?

No. It sends one fixed welcome email to an authenticated, confirmed user. Supabase Auth creates its own confirmation, reset and magic-link tokens; configure custom SMTP for those rather than generating login links in this function.

Was this tested in Lovable?

The TypeScript was checked and the handler ran under Deno against an isolated Runearc API. Authentication success used a local Auth response fixture. Hosted Lovable and Supabase deployment were not exercised, and no external email was delivered.

Sources, read on November 26, 2026

  1. [1]Lovable, branded emails: docs.lovable.dev/features/custom-emails
  2. [2]Lovable, connect Supabase and store secrets: docs.lovable.dev/integrations/supabase
  3. [3]Supabase, Edge Function authorization headers: supabase.com/docs/guides/functions/auth-headers
  4. [4]Supabase, getUser authenticates through the Auth server: supabase.com/docs/reference/javascript/auth-getuser
  5. [5]Supabase, custom SMTP: supabase.com/docs/guides/auth/auth-smtp

Prices change. If something here is out of date or wrong, email hello@runearc.com and we will fix it.

Put Runearc to work

Get inboxes, sending, your own domains and MCP in one workspace. The free plan includes 3 inboxes, 3,000 emails a month and 3 custom domains, with no card.