Ricevi email: lettura

Get Messages

Leggi fino a 50 messaggi per id, con corpo, elenco degli allegati e header.

POSThttps://g.sendcorex.com/v1command: get_messages

Il corpo HTML viene restituito grezzo, senza sanificazione. Sanificalo nel tuo client prima di visualizzarlo.

Argomenti

  • idsstring[]facoltativo

    Fino a 50 id di messaggi.

  • idstringfacoltativo

    Un singolo id di messaggio. Usa questo o ids.

  • includestring[]facoltativo

    Cosa aggiungere a ogni messaggio: body, attachments, headers, full_headers. Predefinito ["body","attachments"].

    es. ["body", "headers", "attachments"]

Avvio rapido

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "get_messages",
        args: {
          ids: [
            "Vj0xQUJDMTIz"
          ],
          include: [
            "body",
            "headers",
            "attachments"
          ]
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

Risposta

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "get_messages",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "messages": [
          {
            "message_uid": "Vj0xQUJDMTIz",
            "thread_id": "thr_9a1c4e72",
            "message_id": "<3f2a1b4c@SCOREX123MB45.prd.sendcorex.com>",
            "folders": [
              "INBOX"
            ],
            "labels": [
              "cliente-vip"
            ],
            "from_name": "Ana Costa",
            "from_email": "ana@client.com",
            "to": [
              {
                "email": "you@yourdomain.com"
              }
            ],
            "cc": [],
            "bcc": [],
            "subject": "Invoice for September",
            "is_read": false,
            "is_starred": false,
            "is_important": false,
            "snoozed_until": null,
            "received_at": "2026-10-09T14:21:07Z",
            "body": {
              "html": "<p>Hi, attached is the invoice.</p>",
              "text": "Hi, attached is the invoice.",
              "external_images": false
            },
            "headers": {
              "content_type": "multipart/mixed",
              "ip_address": "203.0.113.10",
              "is_tls": true,
              "spf_success": true,
              "dkim_success": true,
              "dmarc_success": true,
              "spam_score": 0.4,
              "list_unsubscribe": null
            },
            "attachments": [
              {
                "attachment_id": "Vj0xQVRUMDE",
                "file_name": "invoice.pdf",
                "mime_type": "application/pdf",
                "size_bytes": 48213,
                "inline": false,
                "content_id": null
              }
            ]
          }
        ],
        "not_found": []
      }
    }
  ]
}

Campi della risposta

  • messages[]

    I campi di busta e stato (folders, labels, to, cc, bcc, references, snoozed_until…) più ciò che hai chiesto in include.

  • messages[].body

    { html, text, external_images }. L'HTML è grezzo e non sanificato.

  • messages[].headers

    content_type, ip_address, is_tls, spf_success, dkim_success, dmarc_success, spam_score, list_unsubscribe, list_id, sender_provider (da dove è stata inviata l'email, verificato alla consegna), rules_matched…

  • messages[].agent_score / agent_reasons

    Solo in Agents e NotSubscribing: il punteggio del filtro e cosa l'ha attivato.

  • messages[].full_headers

    Tutto ciò che è in headers più headers_json, received_chain, spf_result, dkim_result, dmarc_result e spam_result.

  • messages[].attachments

    Una lista con attachment_id, file_name, mime_type, size_bytes, inline, content_id e i campi scan_*. Il file non è incluso.

  • not_found

    Id che non esistono in questa casella.

Scarica un allegato

L'elenco degli allegati non contiene mai il binario. Prendi l'attachment_id e scarica il file con la rotta Raw Message.

GET /v1/raw?message_id=<message_uid>&attachment_id=<attachment_id>. Il tipo MIME originale torna in X-Original-Content-Type.

Errori

Gli errori a livello HTTP restituiscono type, code e message. Gli errori marcati CMD tornano dentro il risultato del comando, con HTTP 200.

  • 401TOKEN_EXPIRED

    L'access token è scaduto. Chiama Refresh Token e ripeti la richiesta.

  • 401INVALID_TOKEN

    Il token è malformato, sconosciuto o revocato.

  • 429RATE_LIMITED

    Più di 15 richieste/s o 15 in corso per la stessa IP + casella. Attendi i secondi indicati in Retry-After.

  • CMDINVALID_ARGS

    Un argomento obbligatorio manca o non è valido.

  • CMDINTERNAL

    Errore del server. Il dettaglio viene scritto solo nel log del server.