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

# Email messages

> Get and update draft email messages.

The `email-messages` command lets you view and edit the email message attached to a campaign. Email messages are created automatically when you [create a campaign](https://loops.so/docs/cli/campaigns.md#create).

Use this command when you want to keep email content in Git as `.lmx` files,
review changes locally, and push updates to a draft email message with revision
protection.

## `get`

Get an email message by ID, including its current content and `contentRevisionId`.

```bash theme={"dark"}
loops email-messages get cmn5zia4i0017tzli8ric8giv
```

## `guardian`

Run [Guardian](https://loops.so/docs/creating-emails/guardian.md) content validation on an email message. See [Run Guardian checks](https://loops.so/docs/api-reference/run-guardian-checks.md) for the checks performed and the response format.

```bash theme={"dark"}
loops email-messages guardian cmn5zia4i0017tzli8ric8giv
```

## `preview`

Send a test preview of an email message to the addresses passed in `--email`. The variable fields accepted depend on the parent type:

* Campaign previews accept `--contact-prop`.
* Workflow previews accept `--contact-prop` and `--event-prop`.
* Transactional previews accept `--var` and `--json-vars`.

```bash theme={"dark"}
loops email-messages preview cmn5zia4i0017tzli8ric8giv \
  --email test@example.com \
  --email another@example.com
```

### Flags

| Flag | Short | Description |
| - | - | - |
| `--email` | | Recipient email address (repeatable; at least one required) Required |
| `--contact-prop` | | Contact property as `KEY=value` (repeatable) |
| `--event-prop` | | Event property as `KEY=value` (repeatable) |
| `--var` | `-v` | Data variable as `KEY=value` (repeatable; transactional previews only) |
| `--json-vars` | `-j` | Path to a JSON file of data variables |

## `update`

Update fields on a draft email message. The owning campaign must be in `Draft` status.

```bash theme={"dark"}
loops email-messages update cmn5zia4i0017tzli8ric8giv \
  --expected-revision-id clv8g2x4z012yl70n5o6p7q8r \
  --subject "Welcome to Acme" \
  --preview-text "Here's how to get started" \
  --lmx-file ./email.lmx
```

### Concurrency control

Every update must include either `--expected-revision-id` or `--force`:

* `--expected-revision-id` — pass the `contentRevisionId` from a prior `email-messages get`. The request is rejected with a conflict if the server's revision has advanced, so you don't overwrite a concurrent edit.
* `--force` — fetch the current revision automatically and use it. This overwrites any concurrent edits.

### Setting content

Pass [LMX](https://loops.so/docs/creating-emails/lmx.md) inline with `--lmx` or from a file with `--lmx-file`:

```bash theme={"dark"}
loops email-messages update cmn5zia4i0017tzli8ric8giv \
  --force \
  --lmx-file ./email.lmx
```

### Git workflow

For a safer file-based workflow:

1. Run `loops email-messages get <email-message-id>` and save the current LMX
   in your repository.
2. Commit the `.lmx` file or review it in a branch.
3. Update the draft email with `--lmx-file` and the latest
   `--expected-revision-id`.
4. Save the returned `contentRevisionId` before making another update.

Use `--force` only when you intentionally want to overwrite the latest draft
content.

### Flags

| Flag | Short | Description |
| - | - | - |
| `--expected-revision-id` | `-r` | Last-seen `contentRevisionId` from `email-messages get`. Mutually exclusive with `--force`. |
| `--force` | `-f` | Fetch the current revision and use it (overwrites concurrent edits). Mutually exclusive with `--expected-revision-id`. |
| `--subject` | | Email subject |
| `--preview-text` | | Email preview text |
| `--from-name` | | Sender display name |
| `--from-email` | | Sender username (the part before `@` — the team's sending domain is appended automatically) |
| `--reply-to` | | Reply-to email address |
| `--cc` | | CC email address |
| `--bcc` | | BCC email address |
| `--email-format` | | Email format (`styled` or `plain`) |
| `--language-code` | | Language code, [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) (e.g. `en`, `fr`) |
| `--lmx` | | [LMX](https://loops.so/docs/creating-emails/lmx.md) markup (inline). Mutually exclusive with `--lmx-file`. |
| `--lmx-file` | | Path to a file containing [LMX](https://loops.so/docs/creating-emails/lmx.md) markup. Mutually exclusive with `--lmx`. |
| `--contact-fallback` | | Contact property fallback as `KEY=value` (repeatable). Replaces all server-side contact fallbacks. |
| `--data-fallback` | | Transactional data-variable fallback as `KEY=value` (repeatable). Replaces all server-side data fallbacks. |
| `--event-fallback` | | Event property fallback as `KEY=value` (repeatable). Replaces all server-side event fallbacks. |

At least one content flag (`--subject`, `--preview-text`, `--from-name`, `--from-email`, `--reply-to`, `--lmx`, or `--lmx-file`) must be provided.


## Related topics

- [API Introduction](https://loops.so/docs/api-reference/intro.md)
- [Get an email message](https://loops.so/docs/api-reference/get-email-message.md)
- [Update an email message](https://loops.so/docs/api-reference/update-email-message.md)
- [Render an email message as HTML](https://loops.so/docs/api-reference/render-email-message.md)
- [Send a preview of an email message](https://loops.so/docs/api-reference/preview-email-message.md)
