Receive Emails: Attachments
Upload Attachment
Upload a file before sending. Use the returned compose_uid in send_email, reply, forward or schedule_send.
https://g.sendcorex.com/v1command: upload_attachmentWithout 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.
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.
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_namestringrequiredFile name shown to the recipient.
contentstringrequiredThe file in base64 (a data: URL is accepted too). The request is limited to 1 MB, so about 700 KB of file.
content_typestringoptionalMIME type. Defaults to
application/octet-stream.compose_uidstringoptionalAdd 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_uidSend it with the next uploads and with the send command.
attachment.idUse it in
attachment_idsordelete_attachment.
Errors
HTTP-level errors return type, code and message. Errors marked CMD come back inside the command result, with HTTP 200.
- 401
TOKEN_EXPIREDThe access token has expired. Call Refresh Token and repeat the request.
- 401
INVALID_TOKENThe token is malformed, unknown or revoked.
- 429
RATE_LIMITEDMore than 15 requests/s or 15 in flight for the same IP + mailbox. Wait the number of seconds in Retry-After.
- CMD
INVALID_ARGSA required argument is missing or invalid.
- CMD
INVALID_ATTACHMENTAn attachment content is not valid base64.
- CMD
ATTACHMENTS_TOO_LARGEThe attachments of the email add up to more than 25 MB, or the mailbox already has 500 MB of uploads waiting to be sent.
- CMD
TOO_MANY_OPEN_COMPOSESThe 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.
- CMD
FILE_BLOCKEDA file was blocked by the security scan.
- CMD
ALREADY_SENTThe compose_uid belongs to an email that was already sent.
- CMD
INTERNALServer error. The detail is only written to the server log.