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

# AI Marketing Email

> Generate and send AI-authored marketing emails from an agent run

<iframe src="http://localhost:3000/doc-comp-previews/agent-node-preview?type=send_agent_marketing_email" title="Agent Node Preview" width="100%" height="250px" className="border dark:border-[#1C1C20] rounded-xl" />

## How AI Marketing Email works

**AI Marketing Email** lets your agent generate the subject, preview text, and body content at runtime, then send the email to the selected user using your configured sender. This is the right tool when message content should adapt to the current user context instead of using fixed, pre-approved copy.

The agent uses its prompt instructions and available user data to craft contextually relevant marketing content on every send. This makes AI Marketing Email particularly powerful for lifecycle messaging, personalized promotions, and campaigns where one-size-fits-all copy underperforms. You still control the sender configuration and delivery rules in the builder, so brand identity and send infrastructure remain consistent.

## Configuration

<Columns cols={2}>
  <Card title="Inputs">
    <ParamField path="Prompt" type="string">
      Guidance for when and how the agent should use this tool.
    </ParamField>

    <ParamField path="Send to" type="string" required>
      Target org user ID. Can be selected in the builder or AI-defined during execution.
    </ParamField>

    <ParamField path="From" type="string" required>
      Sender configuration used for delivery.
    </ParamField>

    <ParamField path="Subject" type="string" required>
      Email subject. Typically AI-defined for personalization.
    </ParamField>

    <ParamField path="Preview (optional)" type="string">
      Preview text shown by inbox clients.
    </ParamField>

    <ParamField path="cc" type="string[]">
      Optional CC recipients.
    </ParamField>

    <ParamField path="bcc" type="string[]">
      Optional BCC recipients.
    </ParamField>
  </Card>

  <Card>
    <iframe src="http://localhost:3000/doc-comp-previews/agent-config-preview?type=send_agent_marketing_email" title="Agent Config Preview" width="100%" height="560px" className="" />
  </Card>
</Columns>

<Card title="Outputs">
  <ParamField path="status" type="enum" required>
    The status of the email send operation. Can be `success`, `failure`, or `skipped`.
  </ParamField>

  <ParamField path="to_id" type="string" required>
    The ID of the user that the email was sent to.
  </ParamField>

  <ParamField path="sender_config_id" type="string" required>
    The ID of the sender configuration used for the email.
  </ParamField>

  <ParamField path="email_id" type="string">
    The ID of the email that was sent (available on success).
  </ParamField>

  <ParamField path="create_email_options" type="object">
    The options used when creating the email, including the AI-generated subject, preview text, and body content (available on success).
  </ParamField>

  <ParamField path="create_email_response" type="object">
    The response from the email creation service (available on success).
  </ParamField>

  <ParamField path="code" type="enum">
    The code indicating why the email send operation failed or was skipped. Can be `resend_error`, `duplicate_email`, or `user_marketing_email_opt_out`.
  </ParamField>

  <ParamField path="error_message" type="string">
    The message of the error that occurred (available on failure).
  </ParamField>
</Card>

## Use cases

**Expansion Opportunity**

```
Condition: User has high expansion potential based on usage patterns
Action: Generate benefit-led promotional copy tailored to user's current plan and activity
Outcome: User receives a personalized upgrade offer that speaks to their specific needs
```

**Milestone Celebration**

```
Condition: User completed a significant milestone event (e.g., first integration, 1000th API call)
Action: Generate contextual congratulations with a recommended next best action
Outcome: Timely lifecycle email reinforces engagement and guides the user forward
```

**Personalized Re-Engagement**

```
Condition: User has been inactive for 21+ days with previously high engagement
Action: Generate win-back email referencing the user's past activity and new features they missed
Outcome: Lapsed user receives relevant, personalized messaging that drives return visits
```

**Segment-Specific Campaign**

```
Condition: User matches a dynamic segment (e.g., healthcare vertical, enterprise tier)
Action: Generate industry- or tier-specific campaign content with relevant social proof
Outcome: Marketing email resonates with the recipient's context instead of using generic copy
```

## Best practices

**Prompt Quality**

* Write detailed prompt instructions that specify tone, length, CTA style, and any content constraints.
* Include examples of good and bad output in the prompt to guide the agent's content generation.
* Reference specific user properties the agent should incorporate (e.g., plan name, company size, recent activity).

**Content Guardrails**

* Specify prohibited claims, pricing language, or legal disclaimers that must be included or avoided.
* Test generated content across multiple user profiles to verify the agent produces appropriate variations.
* Monitor `create_email_options` output to audit what the agent actually sent in each email.

**Testing and Iteration**

* Start with a narrow user segment to evaluate AI-generated copy quality before broadening the audience.
* Compare open and click rates against builder-defined Marketing Email sends to measure personalization impact.
* Iterate on prompt instructions based on real send outputs — refine constraints when the agent drifts from expected tone or format.
