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

# Managing Segments

> Learn how to create, retrieve, and delete segments.

Segments are used to group and manage your [Contacts](/docs/guides/dashboard/audiences/contacts). Segments are not visible to your Contacts, but are used for your own internal Contact organization.

## Send emails to your Segment

Segments were designed to be used in conjunction with [Broadcasts](/docs/guides/dashboard/broadcasts/introduction). You can send a Broadcast to an Segment from the Emailr dashboard or from the Broadcast API.

### From Emailr's no-code editor

You can send emails to your Segment by creating a new Broadcast and selecting the Segment you want to send it to.

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

You can include the Unsubscribe Footer in your Broadcasts, which will be automatically replaced with the correct link for each Contact.

### From the Broadcast API

You can also use our [Broadcast API](/docs/api/broadcasts/create-broadcast) to create and send a Broadcast to your Segment.

<CodeGroup>
  ```ts Node.js theme={null} theme={null}
  import { Emailr } from 'emailr';

  const emailr = new Emailr('em_xxxxxxxxx');

  const { data, error } = await emailr.broadcasts.create({
    segmentId: '78261eea-8f8b-4381-83c6-79fa7120f1cf',
    from: 'Acme <onboarding@emailr.dev>',
    subject: 'hello world',
    html: 'Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}',
  });
  ```

  ```php PHP theme={null} theme={null}
  $emailr = Emailr::client('em_xxxxxxxxx');

  $emailr->broadcasts->create([
    'segment_id' => '78261eea-8f8b-4381-83c6-79fa7120f1cf',
    'from' => 'Acme <onboarding@emailr.dev>',
    'subject' => 'hello world',
    'html' => 'Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}',
  ]);
  ```

  ```py Python theme={null} theme={null}
  import emailr

  emailr.api_key = "em_xxxxxxxxx"

  params: emailr.Broadcasts.CreateParams = {
    "segment_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
    "from": "Acme <onboarding@emailr.dev>",
    "subject": "Hello, world!",
    "html": "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}",
  }

  emailr.Broadcasts.create(params)
  ```

  ```ruby Ruby theme={null} theme={null}
  require "emailr"

  Emailr.api_key = "em_xxxxxxxxx"

  params = {
    "segment_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
    "from": "Acme <onboarding@emailr.dev>",
    "subject": "hello world",
    "html": "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}",
  }
  Emailr::Broadcasts.create(params)
  ```

  ```go Go theme={null} theme={null}
  import "fmt"
  import 	"github.com/emailr/emailr-go/v3"

  client := emailr.NewClient("em_xxxxxxxxx")

  params := &emailr.CreateBroadcastRequest{
    SegmentId: "78261eea-8f8b-4381-83c6-79fa7120f1cf",
    From:       "Acme <onboarding@emailr.dev>",
    Html:       "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}",
    Subject:    "Hello, world!",
  }

  broadcast, _ := client.Broadcasts.Create(params)
  ```

  ```rust Rust theme={null} theme={null}
  use emailr_rs::{types::CreateBroadcastOptions, Emailr, Result};

  #[tokio::main]
  async fn main() -> Result<()> {
    let emailr = Emailr::new("em_xxxxxxxxx");

    let segment_id = "78261eea-8f8b-4381-83c6-79fa7120f1cf";
    let from = "Acme <onboarding@emailr.dev>";
    let subject = "hello world";
    let html = "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}";

    let opts = CreateBroadcastOptions::new(segment_id, from, subject).with_html(html);

    let _broadcast = emailr.broadcasts.create(opts).await?;

    Ok(())
  }
  ```

  ```java Java theme={null} theme={null}
  Emailr emailr = new Emailr("em_xxxxxxxxx");

  CreateBroadcastOptions params = CreateBroadcastOptions.builder()
      .segmentId("78261eea-8f8b-4381-83c6-79fa7120f1cf")
      .from("Acme <onboarding@emailr.dev>")
      .subject("hello world")
      .html("Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}")
      .build();

  CreateBroadcastResponseSuccess data = emailr.broadcasts().create(params);
  ```

  ```csharp .NET theme={null} theme={null}
  using Emailr;

  IEmailr emailr = EmailrClient.Create( "em_xxxxxxxxx" ); // Or from DI

  var resp = await emailr.BroadcastAddAsync(
      new BroadcastData()
      {
          DisplayName = "Example Broadcast",
          SegmentId = new Guid( "78261eea-8f8b-4381-83c6-79fa7120f1cf" ),
          From = "Acme <onboarding@emailr.dev>",
          Subject = "Hello, world!",
          HtmlBody = "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}",
      }
  );
  Console.WriteLine( "Broadcast Id={0}", resp.Content );
  ```

  ```bash cURL theme={null} theme={null}
  curl -X POST 'https://api.emailr.dev/broadcasts' \
       -H 'Authorization: Bearer em_xxxxxxxxx' \
       -H 'Content-Type: application/json' \
       -d $'{
    "segment_id": "78261eea-8f8b-4381-83c6-79fa7120f1cf",
    "from": "Acme <onboarding@emailr.dev>",
    "subject": "hello world",
    "html": "Hi {{{FIRST_NAME|there}}}, you can unsubscribe here: {{{EMAILR_UNSUBSCRIBE_URL}}}"
  }'
  ```
</CodeGroup>

## How to customize the unsubscribe link in my Broadcast?

Emailr generates a unique link for each recipient and each Broadcast. You can use `{{{EMAILR_UNSUBSCRIBE_URL}}}` as the link target.

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

## Automatic Unsubscribes

When you send emails to your Segment, Emailr will automatically handle the unsubscribe flow for you.

<img alt="Screenshot placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

If a Contact unsubscribes from your emails, they will be presented with a preference page.

* If you don't have any [Topics](/docs/guides/dashboard/topics/introduction) configured, the Contact will be unsubscribed from all emails from your account.
* If you have [Topics](/docs/guides/dashboard/topics/introduction) configured, the Contact will be presented with a preference page where they can subscribe or unsubscribe from specific types of emails (all `public` Topics will be shown).

Learn more about [managing your unsubscribe list](/docs/guides/dashboard/audiences/managing-unsubscribe-list) or [customizing your unsubscribe page](/docs/guides/dashboard/settings/unsubscribe-page).

<Info>
  Whenever possible, you should add a [Topic to your
  Broadcast](/docs/guides/dashboard/topics/introduction), as this will allow your Contacts
  to unsubscribe from specific types of emails (instead of unsubscribing from
  all emails from your account).
</Info>

## Export your data

Admins can download your data in CSV format for the following resources:

* Emails
* Broadcasts
* Contacts
* Segments
* Domains
* Logs
* API keys

<Info>Currently, exports are limited to admin users of your team.</Info>

To start, apply filters to your data and click on the "Export" button. Confirm your filters before exporting your data.

<img alt="Video placeholder" src="https://mintcdn.com/emailrdev/tSm2WeCvU8-lHmTx/images/placeholder.svg?fit=max&auto=format&n=tSm2WeCvU8-lHmTx&q=85&s=93891ced94bad8f8c38f90b5be99f73c" width="800" height="450" data-path="images/placeholder.svg" />

If your exported data includes 1,000 items or less, the export will download immediately. For larger exports, you'll receive an email with a link to download your data.

All admins on your team can securely access the export for 7 days. Unavailable exports are marked as "Expired."

<Note>
  All exports your team creates are listed in the
  [Exports](https://app.emailr.dev/dashboard) page under **Settings** > **Team** >
  **Exports**. Select any export to view its details page. All members of your
  team can view your exports, but only admins can download the data.
</Note>
