Receive Emails: Attachments

Upload Attachment

Upload a file before sending. Use the returned compose_uid in send_email, reply, forward or schedule_send.

POSThttps://g.sendcorex.com/v1command: upload_attachment
i

Without compose_uid a new one is created. Send it back with the next files of the same email. Each file is scanned before it is saved.

i

For one-off files you can also skip this step and send them inline in attachments of the send command.

!

The whole request is limited to 1 MB, and base64 makes the file about 33% bigger, so this command fits files up to about 700 KB. For bigger files (up to 25 MB) use Upload Large File, which takes the file as binary data.

i

Limits: 20 files and 25 MB per email; per mailbox, 50 emails with uploads not sent yet and 500 MB in total. Uploads not sent within 48 hours, and not used by a draft or scheduled email, are deleted.

Arguments

  • file_namestringrequired

    File name shown to the recipient.

  • contentstringrequired

    The file in base64 (a data: URL is accepted too). The request is limited to 1 MB, so about 700 KB of file.

  • content_typestringoptional

    MIME type. Defaults to application/octet-stream.

  • compose_uidstringoptional

    Add the file to an email you are already putting together.

Quick start

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "upload_attachment",
        args: {
          file_name: "invoice.pdf",
          content: "JVBERi0xLjcKJcfsj6IK…",
          content_type: "application/pdf"
        }
      }
    ]
  },
  { 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);

Response

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

Response fields

  • compose_uid

    Send it with the next uploads and with the send command.

  • attachment.id

    Use it in attachment_ids or delete_attachment.

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.

  • CMDINVALID_ARGS

    A required argument is missing or invalid.

  • CMDINVALID_ATTACHMENT

    An attachment content is not valid base64.

  • CMDATTACHMENTS_TOO_LARGE

    The attachments of the email add up to more than 25 MB, or the mailbox already has 500 MB of uploads waiting to be sent.

  • CMDTOO_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.

  • CMDFILE_BLOCKED

    A file was blocked by the security scan.

  • CMDALREADY_SENT

    The compose_uid belongs to an email that was already sent.

  • CMDINTERNAL

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