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.
https://g.sendcorex.com/v1/attachmentUse 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.
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_namestringrequiredFile name shown to the recipient. Required with a binary body; with multipart the name of the
filepart is used.compose_uidstringoptionalAdd 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_uidSend it with the next uploads of the same email and with the send command.
data.attachment.idUse it in
attachment_idsordelete_attachment.
Request body
Send the file in one of two ways. One file per request.
BinaryThe body is the file itself. Set
Content-Typeto the file type (for exampleapplication/pdf); without it the file is saved asapplication/octet-stream.Multipartmultipart/form-datawith the file in thefilefield. Optional fields:compose_uidandfile_name.
Limits
Per file25 MB.
Per email20 files and 25 MB in total.
Per mailbox50 emails with uploads not sent yet, and 500 MB in total. Sending an email frees its share right away.
Unused uploadsDeleted 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.
- 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.
- 400
INVALID_ARGS`file_name` is missing (binary body), the multipart has no `file` field or has more than one, or `compose_uid` is invalid.
- 400
INVALID_ATTACHMENTThe file is empty or could not be read.
- 400
FILE_BLOCKEDThe file was blocked by the security scan.
- 400
ALREADY_SENTThe `compose_uid` belongs to an email that was already sent.
- 400
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.
- 413
ATTACHMENTS_TOO_LARGEThe file is over 25 MB, the email goes over 25 MB, or the mailbox already has 500 MB of uploads waiting to be sent.
- CMD
INTERNALServer error. The detail is only written to the server log.