Receive Emails: Attachments

Upload Large File

Upload a file of up to 25 MB as binary data, outside the 1 MB JSON of POST /v1. Returns the same compose_uid and attachment id as upload_attachment.

POSThttps://g.sendcorex.com/v1/attachment
i

Use this route for files over about 700 KB. In upload_attachment the file goes in base64 inside the JSON, which is limited to 1 MB, and base64 makes the file about 33% bigger.

i

Then send the compose_uid (and optionally attachment_ids) in send_email, reply, forward, schedule_send or save_draft. Send the same compose_uid again to add more files to the same email.

!

Uploads that are not sent within 48 hours, and that no draft or scheduled email uses, are deleted. Upload the file again if you get ATTACHMENT_MISSING.

Query parameters

  • file_namestringrequired

    File name shown to the recipient. Required with a binary body; with multipart the name of the file part is used.

  • compose_uidstringoptional

    Add the file to an email you are already putting together. With multipart it can also be a form field.

Quick start

import axios from 'axios';
import { readFileSync } from 'node:fs';

const res = await axios.post('https://g.sendcorex.com/v1/attachment', readFileSync('invoice.pdf'), {
  params: { file_name: 'invoice.pdf' },
  headers: {
    Authorization: process.env.SENDCOREX_TOKEN,
    'Content-Type': 'application/pdf',
  },
  maxBodyLength: Infinity,
});

const { compose_uid, attachment } = res.data.data;
console.log(compose_uid, attachment.id);

Response

{
  "type": "SUCCESS",
  "data": {
    "compose_uid": "Vj0xQ01QMDAx",
    "attachment": {
      "id": "6f1c2a9e-4b7d-4e21-9a3f-0c8d5e7b1a42",
      "file_name": "invoice.pdf",
      "size_bytes": 3145728,
      "content_type": "application/pdf"
    }
  }
}

Response fields

  • data.compose_uid

    Send it with the next uploads of the same email and with the send command.

  • data.attachment.id

    Use it in attachment_ids or delete_attachment.

Request body

Send the file in one of two ways. One file per request.

  • Binary

    The body is the file itself. Set Content-Type to the file type (for example application/pdf); without it the file is saved as application/octet-stream.

  • Multipart

    multipart/form-data with the file in the file field. Optional fields: compose_uid and file_name.

Limits

  • Per file

    25 MB.

  • Per email

    20 files and 25 MB in total.

  • Per mailbox

    50 emails with uploads not sent yet, and 500 MB in total. Sending an email frees its share right away.

  • Unused uploads

    Deleted after 48 hours if no draft or scheduled email uses them. Files of a draft or scheduled email stay as long as it exists.

Errors

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

  • 401TOKEN_EXPIRED

    The access token has expired. Call Refresh Token and repeat the request.

  • 401INVALID_TOKEN

    The token is malformed, unknown or revoked.

  • 429RATE_LIMITED

    More than 15 requests/s or 15 in flight for the same IP + mailbox. Wait the number of seconds in Retry-After.

  • 400INVALID_ARGS

    `file_name` is missing (binary body), the multipart has no `file` field or has more than one, or `compose_uid` is invalid.

  • 400INVALID_ATTACHMENT

    The file is empty or could not be read.

  • 400FILE_BLOCKED

    The file was blocked by the security scan.

  • 400ALREADY_SENT

    The `compose_uid` belongs to an email that was already sent.

  • 400TOO_MANY_OPEN_COMPOSES

    The mailbox has 50 emails with uploads that were not sent yet. Send them, or wait for the unused ones to be deleted after 48 hours.

  • 413ATTACHMENTS_TOO_LARGE

    The file is over 25 MB, the email goes over 25 MB, or the mailbox already has 500 MB of uploads waiting to be sent.

  • CMDINTERNAL

    Server error. The detail is only written to the server log.