Attachments
What are Attachments?
An Attachment is a file that is associated with a Message. This can be anything from a PDF invoice to a CSV report or an image(though we don’t recommend sending images in the first email sent. We go more into this in the deliverability section). Your agents can both send Attachments in outgoing Messages and process Attachments from incoming Messages.
Sending Attachments
To send a file, include it in the attachments array when sending a Message. Each object in the array represents one file and must provide either content or url.
content: The Base64 encoded content of your file.url: A URL that AgentMail can download without custom authentication headers or cookies. Redirects and pre-signed URLs are supported, and the final response must be a successful2xxresponse.filename(optional): The name of the file (e.g.,invoice.pdf).content_type(optional): The MIME type of the file (e.g.,application/pdf).
Attachment size limits
If an inline request exceeds 6 MB, the API returns 413 Request Entity Too Large. For larger files, use URL-backed attachments and keep the combined attachment size around 30 MB per message.
To detect the inline limit proactively, measure the complete serialized request and leave room for the message body and metadata. Use url for larger attachments.
Retrieving Attachments
To retrieve an Attachment, you first need its attachment_id. You can get this ID from the attachments array on a Message object. Once you have the ID, you can download the file.
The API response for getting an attachment is the raw file itself, which you can then save to disk or process in memory.
From a Specific Message
If you know the Message an Attachment belongs to, you can retrieve it directly.
From a Specific Thread
Similarly, you can retrieve an Attachment if you know the Thread it’s in, which can be more convenient for multi-message conversations.
Copy for Cursor / Claude
Copy one of the blocks below into Cursor or Claude for complete Attachments usage in one shot.
