# Send email

<mark style="color:green;">`POST`</mark> `https://api.mailhub.sh/v1/send`

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

<table><thead><tr><th width="189">Name</th><th width="213">Type</th><th>Required</th><th>Comment</th></tr></thead><tbody><tr><td><mark style="color:red;"><code>from</code></mark></td><td>string</td><td><mark style="color:red;"><strong>Yes</strong></mark></td><td></td></tr><tr><td><mark style="color:red;"><code>to</code></mark></td><td>string | string[]</td><td><mark style="color:red;"><strong>Yes</strong></mark></td><td></td></tr><tr><td><mark style="color:red;"><code>subject</code></mark></td><td>string</td><td><mark style="color:red;"><strong>Yes</strong></mark></td><td></td></tr><tr><td>bcc</td><td>string[]</td><td>No</td><td></td></tr><tr><td>cc</td><td>string[]</td><td>No</td><td></td></tr><tr><td>reply_to</td><td>string[]</td><td>No</td><td></td></tr><tr><td>layout_identifier</td><td>string</td><td>Yes/No</td><td><p>Layout or page identifier</p><p><br>Eg. <code>tp-xxxxxx</code><br><br>Can't be used with <code>code</code> parameter</p></td></tr><tr><td>code</td><td>string</td><td>Yes/No</td><td>HTML Code you want to send<br><br>Can't be used with <code>layout_identifier</code> parameter</td></tr><tr><td>text</td><td>string</td><td>No</td><td></td></tr><tr><td>tags</td><td><p>object[]</p><pre class="language-javascript"><code class="lang-javascript">{
    name: string
}
</code></pre></td><td>No</td><td></td></tr><tr><td>language</td><td>string</td><td>No</td><td>Language code (eg. <code>en</code>, <code>en_gb</code>, <code>en_au</code>,  ...)<br><a href="/pages/mPJG08elgIf5d9NYRdM6">Documentation</a></td></tr><tr><td>attachments</td><td><p>object[]</p><pre class="language-javascript"><code class="lang-javascript">{
    filename: string, // (optional)
    content: string | Buffer, //(optional)
    path: string, //(optional)
    contentType: string, //(optional)
}
</code></pre></td><td>No</td><td></td></tr></tbody></table>

**Example (payload)**

```json
{
  "layout_identifier": "string", // The identifier of the layout used for generating the email (e.g., "welcome-email")
  "language": "string", // ISO language code, e.g., "en", "fr"
  "variables": { 
    "name": "John Doe"
    // Any dynamic variables used in the template (e.g., { "order_id": "12345" })
  },
  "code": null, // Always null when using layout_identifier; can contain raw HTML if no layout is used (Tailwind compatible)
  "from": "string", // Sender email address
  "to": "string", // Recipient email address
  "subject": "string" // Email subject line
}

```

**Example (request)**

{% tabs %}
{% tab title="cURL" %}

```
curl -X POST "https://api.mailhub.sh/v1/send" \
  --header "Authorization: Bearer <<YOUR_API_KEY_HERE>>" \
  --header "Content-Type: application/json" \
  --data '{
      "layout_identifier": "<<YOUR_LAYOUT_ID>>",
      "variables": {},
      "code": null,
      "from": "Example <example@your-domain.com>",
      "to": "example@mailhub.sh",
      "subject": "hello world",
      ...
  }'
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
fetch(`https://api.mailhub.sh/v1/send`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        Authorization: 'Bearer <<YOUR_API_KEY_HERE>>',
    },
    body: JSON.stringify({
        layout_identifier: '<<YOUR_LAYOUT_ID>>',
        variables: {},
        code: null,
        from: 'Example <example@your-domain.com>',
        to: 'example@mailhub.sh',
        subject: 'hello world',
        ...
    }),
})
    .then((data) => {
        console.log(data);
    })
    .catch((error) => {
        console.error('Error:', error);
    });
```

{% endtab %}

{% tab title=".NET" %}

```csharp
var message = new
{
    layout_identifier = "<<YOUR_LAYOUT_ID>>",
    variables = new { },
    from = "Example <example@your-domain.com>",
    to = "example@mailhub.sh",
    subject = "hello world"
};


RestClient client = new RestClient();
RestRequest request = new RestRequest("https://api.mailhub.sh/v1/send", Method.Post);
request.AddHeader("Authorization", $"Bearer <<YOUR_API_KEY_HERE>>");

request.AddJsonBody(msg, "application/json");

var response = client.Execute(request);
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();
$url = "https://api.mailhub.sh/v1/send";

$data = [
    'layout_identifier' => '<<YOUR_LAYOUT_ID>>',
    'variables' => [],
    'code' => null,
    'from' => 'Example <example@your-domain.com>',
    'to' => 'example@mailhub.sh',
    'subject' => 'hello world'
];

$headers = [
    "Content-Type" => "application/json",
    "Authorization" => "Bearer <<YOUR_API_KEY_HERE>>"
];

try {
    $response = $client->post($url, [
        'headers' => $headers,
        'json' => $data
    ]);

    $responseBody = $response->getBody();
    $decodedResponse = json_decode($responseBody, true);

    print_r($decodedResponse);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
?>
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.mailhub.sh/send-email.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
