---
title: "Send lifecycle emails"
description: "Turn on ready-made lifecycle flows (welcome, a nudge for people who created nothing, first result, credits low, trial ending, abandoned checkout, win-back), keep them under weekly caps, quiet hours and a sunset rule, or write a sequence of your own in code."
canonical_url: "https://nuxt-backend.dev/docs/build/growth/engage/lifecycle-emails"
---
# Send lifecycle emails

> Turn on ready-made lifecycle flows (welcome, a nudge for people who created nothing, first result, credits low, trial ending, abandoned checkout, win-back), keep them under weekly caps, quiet hours and a sunset rule, or write a sequence of your own in code.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [API reference](https://nuxt-backend.dev/docs/reference/api/workflows)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/convex/integrations/workflows.ts)

Write to people at the moments that matter, without a cron job of your own. You get two ways. The **ready-made flows** cover the usual moments, from the welcome to the win-back, and run on Resend Automations. A **sequence** of your own is a durable workflow in your code, for anything the flows don't cover.

**What Resend does natively** (checked on 2026-10-25, [Automations](https://resend.com/docs/dashboard/automations/introduction)): automations with a trigger event, delays, waits for another event, conditions and run logs, created in its dashboard or through its API. A send step uses a published template. Resend adds no unsubscribe link to it: the template carries `{{{RESEND_UNSUBSCRIBE_URL}}}`.

**What the package adds:** the flows, their templates in your brand, the events that start and stop them, sending caps, the sunset rule, and sequences as code. Polar keeps sending its own receipts and billing reminders, and no flow repeats them.

## The ready-made flows

<table>
<thead>
  <tr>
    <th>
      Flow
    </th>
    
    <th>
      Sent when
    </th>
    
    <th>
      Kind
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        welcome
      </code>
    </td>
    
    <td>
      At sign-up
    </td>
    
    <td>
      Transactional
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        activationNudge
      </code>
    </td>
    
    <td>
      24 hours after sign-up, if the person created nothing
    </td>
    
    <td>
      Lifecycle, under your tips topic
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        firstResult
      </code>
    </td>
    
    <td>
      When their first result is ready, such as a first strip
    </td>
    
    <td>
      Transactional
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        creditsLow
      </code>
    </td>
    
    <td>
      When a spend takes the balance to its low mark
    </td>
    
    <td>
      Transactional
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trialEnding
      </code>
    </td>
    
    <td>
      7 days before a trial of 14 days or more ends, ahead of Polar's own reminder
    </td>
    
    <td>
      Transactional
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        checkoutAbandoned
      </code>
    </td>
    
    <td>
      Once, a day after a signed-in person's checkout expired unpaid
    </td>
    
    <td>
      Marketing, opt-in
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        winBack
      </code>
    </td>
    
    <td>
      7 and 30 days after a paid plan ended
    </td>
    
    <td>
      Marketing, opt-in
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stalled
      </code>
    </td>
    
    <td>
      After 14 days without activity, for an account that was active
    </td>
    
    <td>
      Lifecycle, under your tips topic
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        annualSwitch
      </code>
    </td>
    
    <td>
      After the third monthly payment, suggesting the yearly price
    </td>
    
    <td>
      Marketing, opt-in
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        reviewAsk
      </code>
    </td>
    
    <td>
      Once, a week after <a href="https://nuxt-backend.dev/docs/build/growth/measure#name-your-activation-event">
        activation
      </a>
      
      : the event you name as its <code>
        event
      </code>
      
      , else <code>
        account.activated
      </code>
      
      , which the growth funnel records once per account
    </td>
    
    <td>
      Lifecycle, under your tips topic
    </td>
  </tr>
</tbody>
</table>

- **Transactional** flows answer something on the person's account and carry no offer.
- **Lifecycle** flows go under a topic people may leave, such as `tips`, declared on `setupEmail` ([Let people choose their emails](https://nuxt-backend.dev/docs/build/email/preferences)). Where tips count as marketing under your law, make that topic opt-in too ([Follow email law](https://nuxt-backend.dev/docs/ship/compliance/email-law); not legal advice).
- **Marketing** flows go only to people who opted into a marketing topic, such as `offers`.

A billing event, such as a payment, an expired checkout or a plan that ended, starts a lifecycle or marketing email only for people who opted into that flow's topic, and never inside a receipt. An opt-out topic such as `tips` does not count as opting in for these: a flow a billing event starts needs a topic people joined on purpose.

Each flow stops when its reason goes away: a nudge stops once the person creates something, a win-back once they subscribe again.

## Turn them on

Name the flows you want on `setupEmail`, and the topic each lifecycle or marketing flow goes under:

```ts [backend/email.ts]
import { setupEmail } from 'nuxt-backend/email'
import { components } from './_generated/api'

export const email = setupEmail(components, {
  brand: { name: 'Panels', address: '1 Ink Street, Lisbon, Portugal' },
  topics: {
    tips: { name: 'Tips', description: 'How to get more out of Panels, at most weekly.', subscribedByDefault: true },
    offers: { name: 'Offers', description: 'Discounts and plan news, a few times a year.', subscribedByDefault: false },
  },
  lifecycle: {
    welcome: true,
    activationNudge: { topic: 'tips' },
    firstResult: { event: 'app.strip_ready' },
    creditsLow: true,
    trialEnding: true,
    checkoutAbandoned: { topic: 'offers' },
    winBack: { topic: 'offers', days: [7, 30] },
  },
  caps: { perWeek: 2, quietHours: { start: '21:00', end: '08:00' }, sunsetAfterDays: 180 },
})
```

Each flow takes `topic` (required for a lifecycle or marketing flow), `event` (`firstResult` and `reviewAsk`: an event of your own), `until` (`activationNudge`: the event that says the person created something, `firstResult`'s by default) or `days` (`winBack`, `[7, 30]` by default); `true` turns on a flow that needs none of them.

Then run `npx nuxt-backend email sync`. It creates each flow's template at Resend, in your brand's layout and in your default language, and an automation that sends it on the flow's event, with the unsubscribe placeholder and your postal address in every non-transactional template. Once every template and automation exists, it keeps the flows' settings on the deployment, so a flow starts nothing until the sync has made them. A sync that can't make them, with no key, a key that may only send or a refusal from Resend, keeps nothing. A template is made once: edit its copy in Resend's editor, and a later sync leaves it as you left it. To change the words before the first sync, override the `backend.email.lifecycle.<flow>` messages ([Send email in each reader's language](https://nuxt-backend.dev/docs/build/email/templates/languages)).

With `welcome` on, the flow sends the welcome at sign-up in place of the packaged `welcome` email. Without it, or before `email sync` has made it, the packaged one goes as before.

### What starts and stops each flow

The package starts and stops each person's run of a flow from its own events, so nothing more is needed in your code. Each email the run sends is one event to Resend, `lifecycle.<flow>` in snake case (`lifecycle.win_back`), which the flow's automation listens for.

<table>
<thead>
  <tr>
    <th>
      Flow
    </th>
    
    <th>
      Starts on
    </th>
    
    <th>
      Stops on
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        welcome
      </code>
      
      , <code>
        activationNudge
      </code>
    </td>
    
    <td>
      An account's sign-up
    </td>
    
    <td>
      The nudge: its <code>
        until
      </code>
      
       event
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        firstResult
      </code>
    </td>
    
    <td>
      The <code>
        event
      </code>
      
       you name, which you send with <a href="https://nuxt-backend.dev/docs/build/growth/engage/automations#track-an-event">
        <code>
          email.automations.track
        </code>
      </a>
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        reviewAsk
      </code>
    </td>
    
    <td>
      The <code>
        event
      </code>
      
       you name, as <code>
        firstResult
      </code>
      
      's; without one, the account's <code>
        account.activated
      </code>
      
       (<a href="https://nuxt-backend.dev/docs/build/growth/measure#name-your-activation-event">
        Measure growth
      </a>
      
      )
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        creditsLow
      </code>
    </td>
    
    <td>
      <code>
        billing.credits_low
      </code>
      
      , to the account, or a workspace's owners
    </td>
    
    <td>
      
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        trialEnding
      </code>
    </td>
    
    <td>
      <code>
        billing.subscription_created
      </code>
      
       with a trial of 14 days or more
    </td>
    
    <td>
      <code>
        billing.subscription_canceled
      </code>
      
      , <code>
        billing.subscription_revoked
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        checkoutAbandoned
      </code>
    </td>
    
    <td>
      <code>
        billing.checkout_abandoned
      </code>
      
      , which <code>
        setupBilling({ lifecycle: { abandonedCheckout: true } })
      </code>
      
       records (<a href="https://nuxt-backend.dev/docs/build/billing/events">
        React to billing events
      </a>
      
      )
    </td>
    
    <td>
      <code>
        billing.order_paid
      </code>
      
      , <code>
        billing.subscription_created
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        winBack
      </code>
    </td>
    
    <td>
      <code>
        billing.subscription_revoked
      </code>
      
      : the plan ended
    </td>
    
    <td>
      <code>
        billing.subscription_created
      </code>
      
      : they subscribed again
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stalled
      </code>
    </td>
    
    <td>
      14 days after the last activity of an account that came back after its first day
    </td>
    
    <td>
      Each visit moves the day on
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        annualSwitch
      </code>
    </td>
    
    <td>
      The third monthly <code>
        billing.order_paid
      </code>
    </td>
    
    <td>
      
    </td>
  </tr>
</tbody>
</table>

The `billing.*` events are the ones on the [activity trail](https://nuxt-backend.dev/docs/reference/backend/events).

The win-back's event carries the cancellation `reason` that `billing.subscription_canceled` recorded, such as `too_expensive` or `unused`, when the customer gave one. Use it in a condition of the flow's automation, or in its template, to fit the message to why they left ([Handle cancellations and win people back](https://nuxt-backend.dev/docs/build/growth/engage/cancel-flow#win-people-back)).

## Caps, quiet hours and the sunset rule

`caps` applies across lifecycle and marketing email, the flows, your sequences and announcements alike. Transactional email is never capped.

- **perWeek**: at most this many lifecycle and marketing emails per person in seven days. An email over the cap is skipped, not queued.
- **quietHours**: no lifecycle or marketing email in this window of the person's local time, from their profile's time zone, else the browser's at sign-up. A send in the window waits for its end.
- **sunsetAfterDays** (default 180): no lifecycle or marketing email to someone who has neither clicked an email nor used the app in this many days. They keep getting transactional email and stay subscribed. Writing to them again starts with a new sign-in.

Opens don't count as engagement. Apple's Mail Privacy Protection loads every image, so an "open" says nothing. Clicks and app activity do.

## Two senders

Transactional mail goes out from `EMAIL_FROM`, and lifecycle and marketing mail from `EMAIL_MARKETING_FROM`. Put them on separate subdomains, such as `mail.panels.example` and `news.panels.example`. A complaint about a newsletter then never costs a sign-in code its inbox placement. `email sync` checks each subdomain's DMARC record ([Get email into inboxes](https://nuxt-backend.dev/docs/build/email/delivery/deliverability)).

## Declare a sequence

A sequence is a [workflow](https://nuxt-backend.dev/docs/build/data/jobs/workflows) whose steps send email. Each step sleeps its delay durably, through restarts and deploys, then sends through the backend component, so every message is delivery-tracked. The scaffolded `backend/workflows.ts` holds an onboarding sequence, built with `defineEmailSequence(workflow, components, { args, steps })`:

```ts [backend/workflows.ts]
import { defineEmailSequence, setupWorkflows } from 'nuxt-backend/workflows'
import { v } from 'convex/values'
import { components } from './_generated/api'

export const workflow = setupWorkflows(components)

// Runs once on sign-up, started from auth.ts's onUserCreated.
export const onSignup = defineEmailSequence(workflow, components, {
  args: { userId: v.string(), email: v.string(), name: v.string() },
  steps: [
    {
      after: 3 * 24 * 60 * 60 * 1000, // three days after the welcome email
      email: ({ email, name }) => ({
        to: email,
        subject: 'How is your first strip going?',
        text: `Hi${name ? ` ${name}` : ''}, reply to this email if anything is in your way.`,
      }),
    },
  ],
})
```

Each step is `{ after, email }`:

- **after** is the delay in milliseconds from the previous step, slept durably by the workflow component. It survives restarts and deploys, as long as a deploy leaves a running sequence's steps as they were ([Change a sequence that is running](#change-a-sequence-that-is-running)).
- **email(data)** receives the workflow's args and returns `{ to, subject, html?, text? }`, or `null` to skip the step, for a person who already did what the nudge asks.

Every message goes through the backend component, so it is delivery-tracked like any other [send](https://nuxt-backend.dev/docs/build/email/sending). Cancel a running sequence with `workflow.cancel(ctx, id)`. `EmailSequenceStep<Data>` is exported for steps you build elsewhere.

## It follows the account

A sequence started with a `userId` reads the account before each email. A step gets the account's current `email` and `name` in place of the ones the sequence started with. A person who changed their address since sign-up gets the next email at the new one. A sequence whose account was deleted ends there, and nobody is written to. One started without a `userId` sends to the data it was started with.

With [email preferences](https://nuxt-backend.dev/docs/build/email/preferences), a step takes a `topic` too, so a person who left the topic gets no more of the sequence's emails.

## In the layout, in the reader's language

Every step's email goes into the layout the package's own emails use, the brand's header and the footer included ([Brand your emails](https://nuxt-backend.dev/docs/build/email/templates/theme)). The step gets the render context as its second argument: `t`, `locale` and `brand`, in the recipient's language. That is the account's `user.locale` for a sequence started with a `userId`, else a `locale` arg it was started with. Pass your `email` instance for its brand and its `messages`. Without it, the brand comes from `EMAIL_FROM` and `SITE_URL`, and `t` reads English:

```ts [backend/workflows.ts]
import { html } from 'nuxt-backend/email'
import { email } from './email'

export const onSignup = defineEmailSequence(workflow, components, {
  email,
  args: { userId: v.string(), email: v.string(), name: v.string() },
  steps: [
    {
      after: 3 * 24 * 60 * 60 * 1000,
      email: ({ email, name }, { t }) => ({
        to: email,
        subject: t('onboarding.checkIn'),
        html: html`<p>${t('onboarding.checkInBody', { name })}</p>`,
        text: t('onboarding.checkInBody', { name }),
      }),
    },
  ],
})
```

Build `html` with the `html` tag from `nuxt-backend/email`: it escapes every value it interpolates, so a name cannot put markup into the email. An `html` that is a whole document already (`<html …>`) is sent as it is. `backend/email.ts` must not import `workflows.ts`, or the import cycle leaves `email` undefined here. [Send email in each reader's language](https://nuxt-backend.dev/docs/build/email/templates/languages) covers the messages.

## Start it on sign-up

The scaffolded `backend/auth.ts` starts the sequence from `setupAuth`'s `onUserCreated` hook. The packaged welcome email always goes out at sign-up, so the sequence starts with what comes after it:

```ts [backend/auth.ts]
import { workflow } from './workflows'

export const { authComponent, createAuth, getAuthUser /* … */ } = setupAuth(components, query, {
  email,
  rateLimiter,
  onUserCreated: async (ctx, user) => {
    await workflow.start(ctx, internal.workflows.onSignup, {
      userId: user.id, email: user.email, name: user.name,
    })
  },
})
```

<tip>

The `ctx` passed to `onUserCreated` is a full mutation or action ctx, so it can start a workflow directly ([Hook into sign-in and sign-up](https://nuxt-backend.dev/docs/build/auth/sign-in/hooks)).

</tip>

## Change a sequence that is running

The workflow component replays each run against your code to pick up where it slept, and checks every step the run already took against the step your code takes now. A run whose steps changed under it fails when it next wakes. Once a run has passed a step, it fails on a step added, dropped or moved, or an `after` changed to or from `0`, which adds or drops a sleep.

The email a step sent is not checked again. A replay renders it anew, with today's copy, translations, brand and layout, and never sends it twice. A copy edit, a new translation, another `EMAIL_FROM` or a package release that changes the layout leaves a running sequence alone; its next emails go out as they read now.

A new length for a sleep is safe, and so is any change to a step no run has reached yet. For the rest, choose one:

- **Version it.** Put the change on a new export (`onSignupV2`), start new runs there, and keep the old export as it was until its runs finish.
- **Stop the running ones.** `workflow.listByName` finds them, and `workflow.cancel(ctx, id)` stops each.

Starting a run again sends every step again, so change its steps before you do.

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Situation
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        email sync
      </code>
      
       has not run since a flow was turned on
    </td>
    
    <td>
      <code>
        doctor
      </code>
      
       names the flow (<code>
        email-flows
      </code>
      
      ), and it starts nothing
    </td>
  </tr>
  
  <tr>
    <td>
      A sign-up cannot reach the flows
    </td>
    
    <td>
      Logged <code>
        email.lifecycle_unstarted
      </code>
      
      : no sign-up flow starts for the account, and the packaged welcome goes instead
    </td>
  </tr>
  
  <tr>
    <td>
      The person left the flow's topic
    </td>
    
    <td>
      The flow sends nothing more to them
    </td>
  </tr>
  
  <tr>
    <td>
      A send would pass <code>
        perWeek
      </code>
      
       or fall in quiet hours
    </td>
    
    <td>
      Skipped and logged (<code>
        email.skipped_capped
      </code>
      
      ), or held to the window's end. Resend's run log lists only the emails that went.
    </td>
  </tr>
  
  <tr>
    <td>
      Outside <code>
        production
      </code>
    </td>
    
    <td>
      Flows send in test mode, like every send: only to Resend's test addresses (<a href="https://nuxt-backend.dev/docs/start/concepts/environments">
        Environments
      </a>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      A flow names a topic <code>
        setupEmail
      </code>
      
       does not declare, or lacks the <code>
        event
      </code>
      
       it starts on
    </td>
    
    <td>
      <code>
        setupEmail
      </code>
      
       throws when the deployment loads, naming the flow
    </td>
  </tr>
  
  <tr>
    <td>
      An account is erased
    </td>
    
    <td>
      Its contact, and every run waiting for it, go with it
    </td>
  </tr>
</tbody>
</table>

## Limits

- **Resend's plan limits apply.** Automations, contacts and sends count against your Resend plan.
- **One language per template.** A flow's template at Resend is written once, in your default language. For per-language copy, use a sequence, which renders in the reader's language.
- **No one-click unsubscribe header.** Resend sends a flow's email, so its link to leave is Resend's `{{{RESEND_UNSUBSCRIBE_URL}}}` in the template; the RFC 8058 header the package adds to its own sends is not on it.
- **Checked when due, not when sent.** The package checks the topic, the caps and the sunset rule as a step comes due, then hands it to Resend, which sends at once.
- **Caps count what the package sends.** An automation you build yourself in Resend's dashboard is not capped ([Feed the provider's automations](https://nuxt-backend.dev/docs/build/growth/engage/automations)).
- **Polar's own emails are not counted.** Receipts and billing reminders come from Polar ([Customer emails and notifications](https://nuxt-backend.dev/docs/build/billing/events/customer-emails)).

## Test it

Sign up with a Resend test address and read the welcome back with the dev inbox:

```bash
npx nuxt-backend inbox delivered+welcome@resend.dev --json
```

For a sequence, run the workflow in a convex-test app and assert on the sends the test records ([Test backend functions](https://nuxt-backend.dev/docs/develop/testing/functions)).

## Related

- [Feed the provider's automations](https://nuxt-backend.dev/docs/build/growth/engage/automations): automations you build in Resend's dashboard.
- [Let people choose their emails](https://nuxt-backend.dev/docs/build/email/preferences): the topics flows go under.
- [Handle cancellations and win people back](https://nuxt-backend.dev/docs/build/growth/engage/cancel-flow): the cancellation the win-back follows.
- [Workflows](https://nuxt-backend.dev/docs/build/data/jobs/workflows): the durable runs a sequence is built on.
- [Resend](https://nuxt-backend.dev/docs/services/resend): the account, the API key and the sending domain.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
