# Implementación API transaccionales

### **Nombre del servicio**

&#x20;          <mark style="color:red;">POST</mark> <https://api.envialosimple.email/api/v1/mail/send>

### Método de autenticación

&#x20;           Authorization: Bearer \<clave API>

{% hint style="info" %}
Para mas detalle de cómo generar la clave API ver: [Cómo enviar emails desde la API](https://app.gitbook.com/s/fheXereqzBFhNKomK0TM/como-enviar-emails-desde-la-api)
{% endhint %}

### Parámetros

<table><thead><tr><th width="256">Nombre</th><th width="103">Tipo </th><th>Descripción</th></tr></thead><tbody><tr><td>from</td><td>string</td><td><p>Remitente del email. Requerido. Este campo puede informarse con varios formatos:</p><p>       info@empresa.com</p><p>       Empresa &#x3C;info@empresa.com></p><p>       {"email": "info@empresa.com "}</p><p>       {"email": "info@empresa.com ", "name": "Empresa"}</p></td></tr><tr><td>to</td><td>string</td><td><p>Destinatario del email. Requerido. Este campo puede informarse con varios formatos:</p><p>cliente@prueba.com</p><p> Cliente &#x3C;cliente@prueba.com>{"email":"cliente@prueba.com"}</p><p> {"email":"cliente@prueba.com", "name": "Cliente"}</p></td></tr><tr><td>subject</td><td>string</td><td>Asunto del correo. Requerido.</td></tr><tr><td>html</td><td>string</td><td><p>Contenido del email en html.</p><p>Requerido informar el contenido en html o text o templateID.</p></td></tr><tr><td>text</td><td>string</td><td><p>Contenido del email en texto plano. </p><p>Requerido informar el contenido en html o text o templateID.</p></td></tr><tr><td>templateID</td><td>string</td><td><p>Contenido del email desde una plantilla. Debe informarse el ID de la plantilla. </p><p>Requerido informar el contenido en html o text o templateID.</p></td></tr><tr><td>attachments</td><td>object[]</td><td><p>Archivos adjuntos al email. Opcional.</p><p>En el contenido del correo electrónico podrán adjuntarse como archivos normales o dejarlos embebidos en el código usando la sintaxis dentro del código html <code>&#x3C;img src="cid:id"/>.</code></p></td></tr><tr><td>attachments.*.disposition</td><td>string</td><td><p>Tipo de adjuntos. Requerido. Valores posibles:</p><p>inline -> Embebidos en el diseño. Sólo para los contenidos html, no puede usasrse en plantillas.</p><p>attachment -> Adjuntos al email (comunes)</p></td></tr><tr><td>Attachments.*.id</td><td>string</td><td><p>Id del adjunto para incorporarlo embebido dentro del html.</p><p>Sólo requerido para attachments.disposition = inline.</p></td></tr><tr><td>attachments.*.filename</td><td>string</td><td>Nombre del archivo adjunto. Requerido.</td></tr><tr><td>attachments.*.disposition</td><td>string</td><td><p>Tipo de adjuntos. Requerido. Valores posibles:</p><p>inline -> Embebidos en el diseño</p><p>attachment -> Adjuntos normales (debajo del email)</p></td></tr><tr><td>attachments.*.content</td><td>string</td><td>Contenido del adjunto en Base64. Máximo: 15MB. Requerido.</td></tr><tr><td>substitutions</td><td>object[]</td><td><p>Variables. Opcional.</p><p>Estos valores serán reemplazados en el contenido del correo electrónico utilizando el formato {{var}}. Se puede utilizar en los campos de asunto, html y texto.</p></td></tr><tr><td>substitutions.*.var</td><td>string</td><td><p>La etiqueta tendrá el nombre de la variable y dentro el valor con el cual deberá reemplazarse.</p><p>OBS: En el valor no pueden inyectarse entidades HTML (ejemplo &#x3C;p>, &#x3C;h1>, etc).</p></td></tr></tbody></table>

### Ejemplos

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
curl --location 'https://api.envialosimple.email/api/v1/mail/send' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYX..jE2NzgzOTA0MjYsImV' \
--header 'Content-Type: application/json' \
--data-raw '{
	"from": "notificaciones@empresa.com",
    "to": "cliente@prueba.com",
    "subject": "Hola {{nombre}} ya está disponible tu factura",
	"html": "<html><img src=\"cid:logo\"/> <br> <h4> <b>Hola {{nombre}} {{apellido}}</b> </h4> <p> Adjuntamos tu factura del mes {{mes}} </p> </html>",
    "substitutions": {
        "nombre": "Juan",
        "apellido": "Pérez",
        "mes": "02/2023"
    },
    "attachments": [
        {
            "id": "logo",
            "filename": "logo.jpg",
            "disposition": "inline",
            "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
        },
        {
            "disposition": "attachment",
            "filename": "factura.doc",
            "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
        }
    ]
}'
```

{% endcode %}

{% code lineNumbers="true" %}

```json
```

{% endcode %}

&#x20;  &#x20;

<br>
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.envialosimple.email/api/v1/mail/send',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
	"from": "notificaciones@empresa.com",
    "to": "cliente@prueba.com",
    "subject": "Hola {{nombre}} ya está disponible tu factura",
	"html": "<html><img src=\\"cid:logo\\"/> <br> <h4> <b>Hola {{nombre}} {{apellido}}</b> </h4> <p> Adjuntamos tu factura del mes {{mes}} </p> </html>",
    "substitutions": {
        "nombre": "Juan",
        "apellido": "Pérez",
        "mes": "02/2023"
    },
    "attachments": [
        {
            "id": "logo",
            "filename": "logo.jpg",
            "disposition": "inline",
            "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
        },
        {
            "disposition": "attachment",
            "filename": "factura.doc",
            "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
        }
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYX..jE2NzgzOTA0MjYsImV',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
import requests
import json

url = "https://api.envialosimple.email/api/v1/mail/send"

payload = json.dumps({
  "from": "notificaciones@empresa.com",
  "to": "cliente@prueba.com",
  "subject": "Hola {{nombre}} ya está disponible tu factura",
  "html": "<html><img src=\"cid:logo\"/> <br> <h4> <b>Hola {{nombre}} {{apellido}}</b> </h4> <p> Adjuntamos tu factura del mes {{mes}} </p> </html>",
  "substitutions": {
    "nombre": "Juan",
    "apellido": "Pérez",
    "mes": "02/2023"
  },
  "attachments": [
    {
      "id": "logo",
      "filename": "logo.jpg",
      "disposition": "inline",
      "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
    },
    {
      "disposition": "attachment",
      "filename": "factura.doc",
      "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
    }
  ]
})
headers = {
  'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYX..jE2NzgzOTA0MjYsImV',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endcode %}
{% endtab %}

{% tab title="NodeJs" %}
{% code lineNumbers="true" %}

```javascript
var axios = require('axios');
var data = JSON.stringify({
  "from": "notificaciones@empresa.com",
  "to": "cliente@prueba.com",
  "subject": "Hola {{nombre}} ya está disponible tu factura",
  "html": "<html><img src=\"cid:logo\"/> <br> <h4> <b>Hola {{nombre}} {{apellido}}</b> </h4> <p> Adjuntamos tu factura del mes {{mes}} </p> </html>",
  "substitutions": {
    "nombre": "Juan",
    "apellido": "Pérez",
    "mes": "02/2023"
  },
  "attachments": [
    {
      "id": "logo",
      "filename": "logo.jpg",
      "disposition": "inline",
      "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
    },
    {
      "disposition": "attachment",
      "filename": "factura.doc",
      "content": "UEsDBBQABgAIAAAAIQDfpNJsWgEAACAFAAATAAgCW0Nvb…"
    }
  ]
});

var config = {
  method: 'post',
maxBodyLength: Infinity,
  url: 'https://api.envialosimple.email/api/v1/mail/send',
  headers: { 
    'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYX..jE2NzgzOTA0MjYsImV', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});ode
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Errores

<table><thead><tr><th width="374">Error</th><th>Descripción</th></tr></thead><tbody><tr><td>Missing key 'from'</td><td>Es requerido indicar el remitente del email (from).</td></tr><tr><td>Missing key 'to'</td><td>Es requerido indicar el destinatario del email (to).</td></tr><tr><td>Missing key 'subject'</td><td>Es requerido indicar el asunto del email (subject).</td></tr><tr><td>A key 'text' or 'html' or 'templateID' must be provided.</td><td>Es requerido indicar el contenido del email: html y/o text o plantilla.</td></tr><tr><td>Key 'text' too large.</td><td>El campo "text" supera la cantidad máxima de caracteres permitidos (1M).</td></tr><tr><td>Key 'html' too large.</td><td>El campo "html" supera la cantidad máxima de caracteres permitidos (2M).</td></tr><tr><td>Missing key 'disposition' in attachment N.</td><td>Es requerido indicar el tipo de adjunto (disposition) para el adjunto N.</td></tr><tr><td>Missing key 'content' in attachment N.</td><td>Es requerido indicar el contenido (content) para el adjunto N.</td></tr><tr><td>Key 'content' too large in attachment N.</td><td>El campo "content" supera la cantidad máxima de caracteres permitidos (15M) para el adjunto N.</td></tr><tr><td>Missing key 'filename' in attachment N.</td><td>Es requerido indicar el contenido (filename) para el adjunto N.</td></tr><tr><td>Key 'content' is not a valid base64 encoded string in attachment N.</td><td>El campo "content" no contiene un string base64 válido para el adjunto N.</td></tr><tr><td>A key 'id' must be provided when content disposition is 'inline' in attachment N.</td><td>Es requerido indicar el identificador (id) para el adjunto N.</td></tr><tr><td>Substitution for email &#x3C;target-email> contains a key name that exceeds the N chars limit.</td><td>El nombre de la variable supera el límite establecido de N caracteres (64).</td></tr><tr><td>Substitution for email &#x3C;target-email> contains a value that exceeds the N chars limit at key '&#x3C;key-name>'.</td><td>El valor de la variable supera el límite establecido de N caracterers (1024).</td></tr><tr><td>A key 'html' or 'templateID' only.</td><td>Solo debe indicarse un único tipo de contenido: html y/o text o plantilla. </td></tr></tbody></table>


---

# 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://api-transaccional.envialosimple.email/implementacion-api-transaccionales.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.
