> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/api-documentation/recipes/sending-bulk-email-with-dynamic-html.md).

# Sending Bulk Email with Dynamic HTML Content

This recipe shows how to send a different HTML body in every send through the `sendBulkEmail` service, using a single empty mail template prepared in the panel. The content is placed into the template dynamically through the `customParams.body` field of the request body. A separate template is no longer needed for each newsletter, announcement, or HTML generated in an external system: the template is prepared once, and the content changes with every request.

## When to Use

This recipe fits emails whose content changes with every send, such as newsletters, announcements, or HTML produced in another system. The panel holds only one empty template that contains the `@{body}` parameter.

## Prerequisites

* REST API key of the application
* Permission to create email templates in the panel
* A tag or segment that represents the target audience. A segment created with `createSegment` must have `segmentStatus` `READY`; see [Creating and Managing Segments](/netmera-developer-guide/api-documentation/recipes/creating-and-managing-segments.md).

## Step 1: Create an Empty Mail Template in the Panel

Create a new mail template in Netmera Panel and add the following structure to its HTML content. At send time, the template content is filled dynamically through the `@{body}` parameter.

```html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <!--[if mso]><xml>
      <w:WordDocument xmlns:w="urn:schemas-microsoft-com:office:word">
        <w:DontUseAdvancedTypographyReadingMail/>
      </w:WordDocument>
    </xml><![endif]-->
    <meta content="width=device-width, initial-scale=1" name="viewport">
  </head>
  <body class="body">
    @{body}
  </body>
</html>
```

After saving the template, note the **Template ID**. It is available in the URL of the template editing screen and is used as `emailTemplateId` in the next step.

{% hint style="warning" %}
The `@{body}` parameter must be defined exactly in this format and placed in the right spot in the HTML, inside the `<body>` tag.
{% endhint %}

**Expected result:** A saved template that contains only `@{body}`, and a noted Template ID.

## Step 2: Prepare the sendBulkEmail Request

Three fields are filled in the request:

* `emailTemplateId`: The Template ID noted in Step 1
* `customParams.body`: The HTML content to send
* `target`: The target audience, defined as a tag or segment

{% hint style="info" %}
`target` takes only one of `tag`, `segment`, or `sendToAll`. Targeting by external ID is not supported. The examples in this recipe use a tag.
{% endhint %}

```bash
curl https://restapi.netmera.com/rest/3.0/sendBulkEmail \
  --request POST \
  --header 'Accept: */*' \
  --header 'Content-Type: application/json' \
  --header 'X-netmera-api-key: <API_KEY>' \
  --data '{
  "emailTemplateId": <TEMPLATE_ID>,
  "subject": "Sample Subject",
  "customParams": {
    "body": "<h2>Hello!</h2><p>This is a test email.</p><p><a href='\''https://www.netmera.com'\''>Netmera</a></p>"
  },
  "target": {
    "tag": "sample-mail-tag"
  }
}'
```

Replace `<API_KEY>` with the API key of the application and `<TEMPLATE_ID>` with the Template ID noted in Step 1. For service details, see the Trigger an Existing Email Template via API section of the [Notifications](/netmera-developer-guide/api-documentation/rest-api/notifications.md) page.

{% hint style="warning" %}
Put only the content that belongs inside `<body>` in `customParams.body`. The template already holds `<html>`, `<head>`, and `<body>`, so a complete HTML document in `body` produces nested HTML. When the content comes from a system that produces complete documents, send the content of its `<body>`, and move the styles that the content needs into the template or into inline `style` attributes.
{% endhint %}

To send to a segment instead of a tag, use `"target": {"segment": "<SEGMENT_NAME>"}`.

**Expected result:** The request is accepted with HTTP 200.

## Step 3: Track the Response and Reporting

When the request is received successfully, the service returns HTTP 200 and the response contains a `notificationKey` value:

```json
{
  "notificationKey": 1234567
}
```

The returned `notificationKey` is the ID of the email campaign created in Netmera Panel for this send. Use this ID to open the reporting screens and view the send statistics. Every link in `customParams.body` gets an `nm_campid` parameter, so the clicks on the links of the dynamic content appear in the campaign report.

**Expected result:** An email campaign in the panel that matches the `notificationKey`, with its report screen.

## Requests That Are Rejected

The request returns HTTP 400, and no campaign is created, when:

* The subject contains an HTML tag or a line break.
* The HTML of the template is empty.
* The send time is outside the email time restriction of the application.
* The target segment is deleted, does not exist, or has never been calculated.

## Verification Checklist

Verify the following items before and after sending:

* The `@{body}` parameter is defined exactly in this format in the template and placed correctly inside `<body>`
* The template is saved and the Template ID is noted
* The Template ID is sent as `emailTemplateId` in the request
* `customParams.body` holds only the content of `<body>`, not a complete HTML document
* The subject is plain text
* `target` is defined with a tag or segment (targeting by external ID is not supported)
* The `notificationKey` returned in the response is recorded for reporting


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://user.netmera.com/netmera-developer-guide/api-documentation/recipes/sending-bulk-email-with-dynamic-html.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
