> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.chatbridge.mx/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.chatbridge.mx/_mcp/server.

# Send message

POST https://connect.chatbridge.mx/v1/email/messages
Content-Type: application/json

Sends an email to a recipient using a template of the account. The send is **asynchronous**: the API responds `202 Accepted` immediately with a `message_id`; the events (`SENT`, `DELIVERED`, `BOUNCED`, `OPENED`, `CLICKED`...) are notified later through the webhook, correlated by that `message_id`.

Reference: https://docs.chatbridge.mx/email/messages/send-email-message

## Authentication

- `x-api-key` header (required) — Account authentication key. The App-Key must have the Email channel enabled and a sender (mailing output) linked; it cannot be used against the endpoints of other channels.
- `Authorization` header (bearer token, required) — OAuth 2.0 access token issued by `POST /api/oauth/token` (client-credentials). Takes precedence over `x-api-key` when both are sent. See the Authentication section.

## Request

### Body (application/json)

This endpoint expects a SendMessageRequest.

- `to` (string, required) — Recipient address.
- `template_id` (string, required) — Id of an active `GENERAL` template of the account.
- `subject` (string, required) — Subject of the email. It is used as is (no variables).
- `variables` (map from string to SendMessageRequestVariables, optional) — Values for the template placeholders. Keys are the variable names (without braces); values can be strings (up to 10,000 characters), numbers or booleans, and are HTML-escaped.

## Response

### 202

Message accepted for delivery.

- `statusCode` (integer, optional)
- `message` (string, optional)
- `message_id` (string, optional) — Id to correlate the webhook events of this message.

## Errors

### 400 Bad Request Error

The request contains invalid data or violates an Email channel rule. The `errorCode` distinguishes the cause. Body validation errors (missing or malformed fields) respond with `errorCode` 400 and the detail of each field in `message`.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

### 401 Unauthorized Error

Authentication is missing or invalid.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

### 403 Forbidden Error

The API Key does not have access to the Email channel.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

### 404 Not Found Error

The template does not exist, is inactive or belongs to another account.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

### 429 Too Many Requests Error

The requests-per-minute limit was exceeded.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

### 500 Internal Server Error

Unhandled internal error, or the message could not be queued. No email was sent; the request can be retried.

- `message` (string, optional)
- `error` (string, optional)
- `statusCode` (integer, optional)
- `errorCode` (integer, optional)

## Types

### SendMessageRequestVariables

## Examples

**Request**

```json
{
  "to": "customer@example.com",
  "template_id": "6a4bffd5e77672e33fd53050",
  "subject": "Your order is confirmed",
  "variables": {
    "name": "Ana",
    "order_number": 10482
  }
}
```

**Response**

```json
{
  "statusCode": 202,
  "message": "ACCEPTED",
  "message_id": "b3e1c2a4-9f3d-4b7a-8c1e-2a6f9d3b7e10"
}
```

**SDK Code**

```python Messages_sendEmailMessage_example
import requests

url = "https://connect.chatbridge.mx/v1/email/messages"

payload = {
    "to": "customer@example.com",
    "template_id": "6a4bffd5e77672e33fd53050",
    "subject": "Your order is confirmed",
    "variables": {
        "name": "Ana",
        "order_number": 10482
    }
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Messages_sendEmailMessage_example
const url = 'https://connect.chatbridge.mx/v1/email/messages';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"to":"customer@example.com","template_id":"6a4bffd5e77672e33fd53050","subject":"Your order is confirmed","variables":{"name":"Ana","order_number":10482}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Messages_sendEmailMessage_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://connect.chatbridge.mx/v1/email/messages"

	payload := strings.NewReader("{\n  \"to\": \"customer@example.com\",\n  \"template_id\": \"6a4bffd5e77672e33fd53050\",\n  \"subject\": \"Your order is confirmed\",\n  \"variables\": {\n    \"name\": \"Ana\",\n    \"order_number\": 10482\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Messages_sendEmailMessage_example
require 'uri'
require 'net/http'

url = URI("https://connect.chatbridge.mx/v1/email/messages")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"to\": \"customer@example.com\",\n  \"template_id\": \"6a4bffd5e77672e33fd53050\",\n  \"subject\": \"Your order is confirmed\",\n  \"variables\": {\n    \"name\": \"Ana\",\n    \"order_number\": 10482\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Messages_sendEmailMessage_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://connect.chatbridge.mx/v1/email/messages")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"to\": \"customer@example.com\",\n  \"template_id\": \"6a4bffd5e77672e33fd53050\",\n  \"subject\": \"Your order is confirmed\",\n  \"variables\": {\n    \"name\": \"Ana\",\n    \"order_number\": 10482\n  }\n}")
  .asString();
```

```php Messages_sendEmailMessage_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://connect.chatbridge.mx/v1/email/messages', [
  'body' => '{
  "to": "customer@example.com",
  "template_id": "6a4bffd5e77672e33fd53050",
  "subject": "Your order is confirmed",
  "variables": {
    "name": "Ana",
    "order_number": 10482
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Messages_sendEmailMessage_example
using RestSharp;

var client = new RestClient("https://connect.chatbridge.mx/v1/email/messages");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"to\": \"customer@example.com\",\n  \"template_id\": \"6a4bffd5e77672e33fd53050\",\n  \"subject\": \"Your order is confirmed\",\n  \"variables\": {\n    \"name\": \"Ana\",\n    \"order_number\": 10482\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Messages_sendEmailMessage_example
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "to": "customer@example.com",
  "template_id": "6a4bffd5e77672e33fd53050",
  "subject": "Your order is confirmed",
  "variables": [
    "name": "Ana",
    "order_number": 10482
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://connect.chatbridge.mx/v1/email/messages")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```