> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brew.new/llms.txt
> Use this file to discover all available pages before exploring further.

# Send Emails with Lovable

> Add email sending to an app you built in Lovable using the Brew API, wiring automations to your app's real events without leaving your stack.

## Overview

[Lovable](https://lovable.dev) is a platform that builds full-stack web apps from natural language prompts. You can integrate Brew into any Lovable project to send on-brand emails triggered by user actions in your app.

Brew works with Lovable through its REST API. The API needs an API key, so the call runs in a backend Edge Function. Your key never reaches the browser.

## What Brew Handles for You

Building email into an app usually means writing HTML templates, handling unsubscribes, managing bounces, and worrying about deliverability. Brew takes care of all of that so you can focus on your app.

* **On-brand design without HTML.** Describe your email in plain language. Brew generates production-ready, responsive emails that match your brand's colors, fonts, logo, and tone of voice. No HTML coding or email design skills needed.
* **Compliance built in.** Marketing emails (both one-off Emails and Automations) automatically include a physical address and unsubscribe link in the footer. The address comes from your brand's **Details → Mailing address** on the [Brand page](/brand/brand-identity), and the pre-send audit warns when it's missing.
* **Unsubscribe management.** Brew handles the entire unsubscribe flow: a branded unsubscribe page, contact status updates, and automatic suppression from future marketing sends. You don't need to build any of this yourself.
* **Bounce and complaint handling.** Hard bounces are automatically suppressed, protecting your sender reputation without any code on your end.
* **Contact auto-creation.** When you trigger an automation, Brew automatically creates or updates the contact record. No separate contact creation step needed in your app.
* **Works across every email client.** Email HTML is notoriously tricky across Gmail, Outlook, Apple Mail, Yahoo, and mobile. Every email Brew generates is responsive and tested across clients.
* **Analytics without instrumentation.** Opens, clicks, bounces, and deliverability are tracked automatically in Brew's dashboard. No event tracking code required in your Lovable app.

## Ways to Send Emails with Brew

Brew has two types of email, Emails and Automations, and a transactional email is a kind of automation. Here's how each one works in the context of a Lovable app:

| Type | What it does | How it's triggered |
| :- | :- | :- |
| **Automations** | Multi-step email sequences with delays, branching, and conditions. Think welcome series, onboarding drips, or order follow-ups. | Triggered from your Lovable app via API when an event happens (user signs up, places an order, etc.) |
| **Transactional** | Single, immediate account emails like password resets and receipts. | The same fire API as automations: a one-step automation whose send step uses a transactional-purpose sending domain, see the section below. |
| **Emails** | One-time sends to a segment of your audience, what other tools call campaigns. Think newsletters, product announcements, or promotions. | Usually created and sent (or scheduled) in Brew. Your backend can also send one with `POST /v1/sends`. |

**Automations** are triggered directly from your Lovable app using the setup below. **Emails** are usually designed and sent in Brew, so most apps need nothing in Lovable for those.

## Prerequisites

<CardGroup cols="2">
  <Card title="Brew Account" icon="mug-hot">
    Sign up at [brew.new](https://brew.new) and set up your brand.
  </Card>

  <Card title="Verified Domain" icon="globe">
    [Verify your sending domain](/get-started/verify-your-sending-domain) to send emails from your own address.
  </Card>

  <Card title="API Key" icon="key">
    Create a new API key at
    [brew.new/settings/api](https://brew.new/settings/api). For this
    single-brand integration, create a brand-scoped key while the
    intended brand is active.
  </Card>

  <Card title="Lovable Backend" icon="database">
    Use Lovable Cloud or connect your own Supabase project. Either one runs Edge Functions.
  </Card>
</CardGroup>

## Connect Brew to Lovable

These steps wire your Lovable app up to trigger automations.

<Steps>
  <Step title="Set up a backend for your project">
    Edge Functions need a backend. In your Lovable project, open **More → Cloud**.

    Use Lovable Cloud, or click **Already have a Supabase project? Connect it here** to use your own. Then click **Continue** and **Connect** next to your Supabase project.

    A workspace owner or admin must link your Supabase organization to the Lovable workspace before you can connect a project.
  </Step>

  <Step title="Add your Brew API key as a secret">
    In your Lovable project, go to **More → Cloud → Secrets**:

    * Add a new secret with the name `BREW_API_KEY`
    * Paste your Brew API key as the value

    If you connected your own Supabase project, click **Manage secrets** instead. It opens your project's Edge Functions settings in the Supabase dashboard, where you add the same secret.

    Get your API key from [brew.new/settings/api](https://brew.new/settings/api).
  </Step>
</Steps>

***

## Automations

Automations are multi-step email flows you design in Brew. Your Lovable app triggers them when something happens, like a user signing up, placing an order, or abandoning a cart. Brew handles the entire sequence: delays, branching, follow-ups.

<Warning>
  Every marketing recipient must have opted in to hear from you. Importing or syncing contact data into Brew is not permission to email it. See [What You Can Send](/get-started/what-you-can-send).
</Warning>

### Set Up in Brew

<Steps>
  <Step title="Create your automation">
    In Brew, go to the Create page, select **Automation**, and describe the flow you want. For example: *"Create a 3-email welcome series for new users. First email welcomes them, second shares a quick-start guide, third nudges them to book a demo."*
  </Step>

  <Step title="Create the trigger and define your payload">
    Open **Automations**, click **Triggers**, then **New custom trigger**. Give it a descriptive name like `user_signup` or `order_placed`.

    Define the payload fields your app will send, for example `email`, `firstName`, and `plan`. Brew assigns the trigger an ID; copy it for the Lovable prompt.
  </Step>

  <Step title="Publish">
    Publish your automation to make it available through the API.
  </Step>
</Steps>

<Info>
  Learn more about building automations in the [Build an Automation guide](/create-emails/build-an-automation).
</Info>

### Prompt Lovable

Copy and paste this prompt into Lovable's chat:

```
Integrate Brew automation API for triggering email sequences.

API Details:
- Base URL: https://brew.new/api
- Auth: Bearer token using the BREW_API_KEY secret
- Endpoint: POST /v1/automations/triggers/{triggerEventId}/fire
  (the trigger id travels in the URL path, not the body)
- Content-Type: application/json
- Optional header: `Idempotency-Key` (recommended). See [Idempotency](/api-reference/api/idempotency) for replay behavior.

Request body format (fire):
{
  "payload": {
    "email": "user@example.com",
    "firstName": "Jane",
    "plan": "premium"
  }
}

Response format (HTTP 202 Accepted, which means queued, not yet delivered.
A retry with the same Idempotency-Key answers 200 with status "replayed"
and the original run ids):
{
  "triggerInstanceId": "tin_4fZ2kQ9pLm7xR1tV8wYcD",
  "triggerEventId": "tri_user_signup",
  "status": "triggered",
  "automationRunIds": ["jh7acthhe99pq4448xh83gn54x8eennb"],
  "notStarted": [],
  "publishedAutomations": [
    { "automationId": "M3nRk8LqW2xT5vBp9YcZd", "name": "Welcome flow" }
  ],
  "counts": { "automations": 1, "skipped": 0 },
  "warnings": [],
  "receivedAt": "2026-04-08T12:34:56.789Z"
}

Create a Supabase Edge Function called "trigger-automation" that:
1. Reads BREW_API_KEY from environment secrets
2. Accepts triggerEventId and payload in the request body
3. Calls POST https://brew.new/api/v1/automations/triggers/${triggerEventId}/fire with:
     - Authorization: Bearer <BREW_API_KEY>
     - Idempotency-Key: <a stable per-event hash, e.g. `signup-${userId}-${eventTimestamp}`>
4. Returns automationRunIds[], notStarted[] and warnings[] from the response to the client

The "email" field is always required in the payload. triggerEventId is the
stable id returned by POST /v1/automations/triggers (or surfaced in
GET /v1/automations/triggers for integration-provisioned triggers).

Docs: https://docs.brew.new/create-emails/build-an-automation
SDK: https://docs.brew.new/sdks/typescript/agentic-cookbook (use brew.automations.triggers.fire())
```

Lovable will write and deploy the Edge Function and wire it into your app automatically.

### When to Use Automations

* **User signup.** Trigger `user_signup` to start a welcome series
* **Onboarding.** Trigger `onboarding_started` to send a multi-step getting started sequence
* **Trial ending.** Trigger `trial_ending` to send a reminder sequence nudging users to upgrade
* **Re-engagement.** Trigger `user_inactive` to win back users who haven't logged in recently

***

## Transactional Emails

Password resets, receipts, and account notifications have to reach unsubscribed contacts and skip the unsubscribe footer. Brew has no separate API for them.

A transactional email is an automation whose Send Email step uses a sending domain with a **transactional** purpose. The domain purpose is what removes the unsubscribe requirement and delivers to unsubscribed contacts.

The wiring from Lovable matches the automations flow above:

1. Create the trigger
2. Build a one-step automation
3. Pick the transactional-purpose domain on its Send Email step
4. Publish
5. Fire it from the same Edge Function pattern

Reference payload fields in the email as `{{ trigger.* }}` variables, such as `{{ trigger.resetUrl }}`. See [Transactional Email](/create-emails/transactional-email) for the model.

Event-driven marketing emails (welcome, onboarding, re-engagement) use the same flow from a marketing-purpose domain and respect unsubscribes. A trial-ending reminder is transactional, like a receipt, so send it from the transactional-purpose domain.

***

## Test Your Integration

Once Lovable finishes generating the code, trigger the email flow in your app (for example, submitting a signup form). Check your email analytics in Brew to confirm the email was delivered.

## Troubleshooting

<AccordionGroup>
  <Accordion title="Emails are not being sent" icon="triangle-exclamation">
    Check that `BREW_API_KEY` is set under **More → Cloud → Secrets** (or in the Supabase dashboard for your own project). Also verify that your sending domain is [verified in Brew](/get-started/verify-your-sending-domain) by checking **Domains** in the Brew sidebar.
  </Accordion>

  <Accordion title="Getting a 401 Unauthorized error" icon="lock">
    Double-check that the Edge Function is reading the secret correctly. The Authorization header should be `Bearer YOUR_API_KEY` with no extra spaces or quotes.
  </Accordion>

  <Accordion title="Missing required payload fields" icon="code">
    Make sure the `payload` includes `email` and every required field defined in your trigger schema. Field names are case-sensitive.
  </Accordion>

  <Accordion title="Automation not triggering" icon="bolt">
    Verify that at least one bound automation is **Live** in Brew (Draft automations are inert). Check that the event ID in your API call matches the trigger configured in Brew. If `brew.automations.triggers.fire(...)` returns `NO_PUBLISHED_AUTOMATION`, publish at least one bound automation and retry.
  </Accordion>

  <Accordion title="Emails landing in spam" icon="shield-exclamation">
    Make sure you have completed [domain verification](/get-started/verify-your-sending-domain) including DKIM and SPF records. We recommend using a subdomain like `updates.yourdomain.com` for sending.
  </Accordion>

  <Accordion title="Lovable shows build errors" icon="bug">
    Lovable may sometimes show false positive build errors. Test your app live by triggering the actual email flow. If the Edge Function deploys successfully, the integration is likely working.
  </Accordion>
</AccordionGroup>

## Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

<Tabs>
  <Tab title="Self-Service Tools">
    <CardGroup cols="2">
      <Card title="Search Documentation" icon="magnifying-glass" color="#c44925">
        Type in the "Ask any question" search bar at the top left to instantly find relevant documentation pages.
      </Card>

      <Card title="Ask ChatGPT or Claude" icon="robot" color="#c44925" href="#top" className="ask-ai-card">
        Click here to open the **Copy page** menu at the top of this page, then send the page to ChatGPT, Claude, or your editor.
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Talk to Our Team">
    <CardGroup cols="2">
      <Card title="Schedule a Call" icon="calendar" color="#c44925" href="https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ1iYoRUG1J792XQpbuQLjSRRDupr7MwraFK-HQRCtTYdBmrQi8nZu2qXfzKQigb8gbKJK3KN3-R">
        Book time with our founders for personalized guidance on strategy, best practices, or complex implementation questions.
      </Card>

      <Card title="Call Us Directly" icon="phone" color="#c44925">
        Need immediate assistance? Reach us at **+1-(332)-203-2145** for urgent issues or time-sensitive questions.
      </Card>

      <Card title="Slack Channel" icon="slack" color="#c44925">
        Our preferred support channel. You'll receive an invite after signup for direct founder support and fast responses.
      </Card>

      <Card title="Email Support" icon="envelope" color="#c44925" href="mailto:support@brew.new">
        Contact us at **[support@brew.new](mailto:support@brew.new)** for detailed inquiries or if you prefer not to use Slack.
      </Card>
    </CardGroup>
  </Tab>
</Tabs>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.