---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/api-reference/receive-emails/routes/raw-message

Receive Emails: Routes

# Raw Message

Download the raw .eml of a message or one of its attachments as binary data.

GET `https://g.sendcorex.com/v1/raw`

Message ids are base64, so they contain `+`, `/` and `=`. URL-encode them. HTTP libraries do this for you when you pass them as query parameters, as in the examples below.

Attachments are always served as `attachment` with `application/octet-stream`. The original type is in the `X-Original-Content-Type` response header. Treat attachments as untrusted files.

## Query parameters

- `message_id` string required
The `message_uid` of the message.
- `attachment_id` string optional
The `attachment_id` returned by `get_messages`. When set, the attachment is returned instead of the whole email.

## Quick start

```
import axios from 'axios';
import { writeFileSync } from 'node:fs';

const response = await axios.get('https://g.sendcorex.com/v1/raw', {
  params: { message_id: 'Vj0xQUJDMTIz', attachment_id: 'Vj0xQVRUMDE' },
  headers: { Authorization: process.env.SENDCOREX_TOKEN },
  responseType: 'arraybuffer',
});

writeFileSync('attachment.bin', Buffer.from(response.data));
```

## Response

```
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Content-Disposition: attachment
X-Original-Content-Type: application/pdf

<binary data>
```

### Response fields

- `Content-Type`
`message/rfc822` for the raw email, or `application/octet-stream` for an attachment.
- `X-Original-Content-Type`
The real MIME type of the attachment, such as `application/pdf`.

## Download the whole email

Leave out `attachment_id` to get the original message as an `.eml` file.

Node.js

```
import axios from 'axios';
import { writeFileSync } from 'node:fs';

const res = await axios.get('https://g.sendcorex.com/v1/raw', {
  params: { message_id: 'Vj0xQUJDMTIz' },
  headers: { Authorization: process.env.SENDCOREX_TOKEN },
  responseType: 'arraybuffer',
});

writeFileSync('message.eml', Buffer.from(res.data));
```

## Errors

HTTP-level errors return `type`, `code` and `message`. Errors marked CMD come back inside the command result, with HTTP 200.

- 401`MISSING_AUTH_HEADER`
No Authorization header was sent.
- 401`INVALID_TOKEN`
The token is malformed, unknown or revoked.
- 401`TOKEN_EXPIRED`
The access token has expired. Call Refresh Token and repeat the request.
- 429`RATE_LIMITED`
More than 15 requests/s or 15 in flight for the same IP + mailbox. Wait the number of seconds in Retry-After.
