- Find the attachments of an email
- Download an attachment
- Show inline images (images inside the email body)
- Send an email with attachments
- Forward attachments
1. Find the attachments of an email
Attachments are listed inside every email object, in theattachments array. You get them when you list emails or retrieve an email.
Response (part of it)
The attachment object
string
The attachment’s
att_… id. Use it with the email’s id to download the file.string
The file name, for example
report.pdf. Can be empty if the sender didn’t give one.string
The file extension, taken from the name, for example
pdf. Empty when the name has none.integer
Size in bytes.
4296429 is about 4.1 MB.string
The file type (MIME type), for example
application/pdf, image/png, text/csv.string | null
The Content-ID. Only set for images that are shown inside the email body. See Show inline images.
boolean
true: the file is shown inside the email body (usually a logo or a signature image).
false: a normal attachment, shown as a file under the email.Find emails that have attachments
Addhas_attachments=true when you list emails:
folder=INBOX or from=ana@example.com.
2. Download an attachment
string
required
The email’s
email_… id.string
required
The attachment’s
att_… id, from the email’s attachments array.Examples
Let your users download files
Your access token must stay on your server, so your users’ browsers can’t call the engine directly. Instead, add a route in your own app that downloads the file from the engine and passes it on:Laravel route
Errors
See Errors for the error format.
Where the file comes from
You don’t need to do anything for this. It explains why downloads are fast and keep working.- New emails are saved right away, without the files. The engine saves the email and the list of its attachments (name, size, type) first, so a large file never delays new mail or webhooks.
- A background job then copies every file into your workspace’s storage, a few seconds later.
- Downloads come from that copy. They’re fast, and they work even when the IMAP server is slow or down.
- If you download a file before it’s copied, the engine gets it from the provider for you and copies it at the same time.
3. Show inline images
Some emails show images inside the text, for example a company logo in a signature. Those images are sent as attachments withinline: true, and the HTML body points to them with a cid: link instead of a normal URL:
cid:logo@acme, so the image looks broken if you display the body as it is. To fix it, replace each cid: link with a URL that serves the attachment, such as your own download route:
1
Find the inline attachments
Take the attachments that have a
cid, for example { "id": "att_81c4b2d95e6f4a1b8c7d9e0f1a2b3c4d", "cid": "logo@acme" }.2
Replace each cid: link in the body
Replace
cid:logo@acme with your URL for that attachment, for example /emails/email_94a0d77db739407e932c3b97fef44aac/attachments/att_81c4b2d95e6f4a1b8c7d9e0f1a2b3c4d.3
Display the body
The images now load from your app.
Node.js
4. Send an email with attachments
Use Send an email (POST /api/v1/emails) and add the files in one of two ways.
Option A: multipart/form-data (upload files)
Best when you have the files on disk or from an upload form. Put each file in a field namedattachments, and repeat the field for more files. The other fields (account_id, to, subject, body …) are normal text fields.
to, cc and bcc can be a JSON list (as above) or simply ana@example.com, bob@example.com.
Option B: JSON (base64 content)
Best when the file is already in memory, for example generated by your app. Send the file content encoded as base64:object[]
One object per file.
string
default:"attachment"
The name the recipient sees, for example
proposal.pdf.string
default:"application/octet-stream"
The file type, for example
application/pdf.string
required
The file content, base64-encoded.
Size limits
Base64 makes files about 33% bigger, so a 20 MB file becomes about 27 MB in a JSON request. For large files, use multipart. If the provider refuses the email, you get an error with the provider’s reason in
detail (see Errors).reply_to) and drafts.
5. Forward attachments
There’s no separate forward call. To forward an email with its files:- Download each attachment of the original email.
- Send a new email with those files, and with the original’s text in
body.
Node.js
Questions
Why is has_attachments true, but I only see a logo?
Why is has_attachments true, but I only see a logo?
Inline images (
inline: true), like a logo in a signature, are attachments too. Filter on inline: false to show only real file attachments.Can I download an attachment after the user deleted the email?
Can I download an attachment after the user deleted the email?
While the email is in Trash, yes: it’s still an email in the API (with
role: "TRASH"), and its attachments download normally. Once it’s permanently deleted (Trash emptied), the email and its attachments are gone from the API and you get 404. If you need to keep a file, download it and store it in your app when you receive the email.new event.Do webhooks include the files?
Do webhooks include the files?
No. An
email.new event includes the attachment list (id, name, extension, size, mime), not the file content. Download the files you need with the endpoint above.Is there a limit on how many attachments I can send?
Is there a limit on how many attachments I can send?
No fixed number. The total request must stay under 30 MB, and under the provider’s own limit.