Enviar mails

Supervisor
Supervisor
  • Actualización

Nombre del servicio

POST https://api.envialosimple.email/api/v1/mail/send

Método de autenticación

Authorization: Bearer <clave API>

Para más detalle de cómo generar la clave API ver: Cómo enviar emails desde la API

Parámetros

Nombre
Tipo
Descripción
from
string
Remitente del email. Requerido excepto si el contenido es una plantilla y tiene cargados estos valores en la cabecera. Este campo puede informarse con varios formatos:
info@empresa.com
Empresa <info@empresa.com>
{"email": "info@empresa.com "}
{"email": "info@empresa.com ", "name": "Empresa"}
to
string
Destinatario del email. Requerido. Este campo puede informarse con varios formatos:
cliente@prueba.com
Cliente <cliente@prueba.com>{"email":"cliente@prueba.com"}
{"email":"cliente@prueba.com", "name": "Cliente"}
subject
string
Asunto del correo. Requerido.
html
string
Contenido del email en html.
Requerido informar el contenido en html o text o templateID.
text
string
Contenido del email en texto plano.
Requerido informar el contenido en html o text o templateID.
templateID
string
Contenido del email desde una plantilla. Debe informarse el ID de la plantilla.
Ver servicio “Listar plantillas” para obtener un detalle de las mismas.
Requerido informar el contenido en html o text o templateID.
attachments
object[]
Archivos adjuntos al email. Opcional.
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 <img src="cid:id"/>.
attachments.*.disposition
string
Tipo de adjuntos. Requerido. Valores posibles:
inline -> Embebidos en el diseño. Sólo para los contenidos html, no puede usasrse en plantillas.
attachment -> Adjuntos al email (comunes)
Attachments.*.id
string
Id del adjunto para incorporarlo embebido dentro del html.
Sólo requerido para attachments.disposition = inline.
attachments.*.filename
string
Nombre del archivo adjunto. Requerido.
attachments.*.disposition
string
Tipo de adjuntos. Requerido. Valores posibles:
inline -> Embebidos en el diseño
attachment -> Adjuntos normales (debajo del email)
attachments.*.content
string
Contenido del adjunto en Base64. Máximo: 15MB. Requerido.
context
object[]

Variables. Opcional. (Recomendada)
Estos valores reemplazarán las variables definidas en el contenido. Se puede utilizar en los campos de asunto, html y texto.  La etiqueta tendrá el nombre de la variable y dentro el valor con el cual deberá reemplazarse.

Pueden incluirse todo tipo de variables: escalares, arreglos, objetos, etc.

Ejemplo:

"context": {

        "nombre": "Juan",

        "productos": [

            {

                "nombre": "Producto1",

                "precio": 3500

            },

            {

                "nombre": "Producto2",

                "precio": 8500

            }]

     }

substitutions
object[]

Variables. Opcional.

Estos valores reemplazarán las variables definidas en el contenido. Se puede utilizar en los campos de asunto, html y texto.  La etiqueta tendrá el nombre de la variable y dentro el valor con el cual deberá reemplazarse.

Solo pueden incluirse variables escalares.

Ejemplo:

   "substitutions": {

        "nombre": "Juan",

        "apellido": "Pérez",

        "monto": "$8500"

    }

 

Observaciones: Se recomienda usar “context” para informar las variables ya que es más completo debido a que acepta todo tipo de variables. Pero también se acepta “substitutions” para mantener la retrocompatibilidad con versiones anteriores de la API en las que solo podían utilizarse variables escalares.

Ejemplos

  • 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…"
    }
    ]
    }'
  • <?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;

     
  • 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)
  • 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

Errores

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

¿Fue útil este artículo?

Usuarios a los que les pareció útil: 0 de 0

¿Tiene más preguntas? Enviar una solicitud