Download Attachment
GET /api/e2/attachments/:id/:filename
Download an email attachment by email ID and filename. Returns the binary file content with appropriate Content-Type and Content-Disposition headers.
Path Parameters
Email ID that contains the attachment.Example:
eml_abc123Filename of the attachment to download. Will be URL-decoded automatically.Example:
report.pdf or My%20Document.docxResponse
Returns binary file content with appropriate headers: Response Headers:MIME type of the attachment (e.g.,
application/pdf, image/png, text/plain).Falls back to application/octet-stream if unknown.Attachment disposition with filename. Uses both ASCII fallback and UTF-8 encoded filename per RFC 5987.Example:
attachment; filename="report.pdf"; filename*=UTF-8''report.pdfSize of the attachment in bytes.
Cache control header:
private, max-age=3600Attachment Storage
Attachments are stored in two possible locations:- Amazon S3 (Primary) - For emails stored in S3 buckets
- Database (Fallback) - For emails with inline content
- Tries S3 first if bucket and key are available
- Falls back to database content if S3 fetch fails
- Returns appropriate error if neither source is available
Size Limits
The maximum attachment size is determined by your email provider’s limits:
- AWS SES: 10 MB per email (including all attachments)
- Individual attachments: No specific limit, but total email size must not exceed 10 MB
Supported Formats
All attachment types are supported. Common MIME types:| Format | MIME Type | Extension |
|---|---|---|
application/pdf | .pdf | |
| Word Document | application/vnd.openxmlformats-officedocument.wordprocessingml.document | .docx |
| Excel Spreadsheet | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | .xlsx |
| PowerPoint | application/vnd.openxmlformats-officedocument.presentationml.presentation | .pptx |
| ZIP Archive | application/zip | .zip |
| PNG Image | image/png | .png |
| JPEG Image | image/jpeg | .jpg, .jpeg |
| GIF Image | image/gif | .gif |
| Text File | text/plain | .txt |
| CSV File | text/csv | .csv |
| JSON File | application/json | .json |
Error Responses
Error message describing what went wrong.
Additional error details (if available).
Common Error Scenarios
404 - Email Not FoundListing Email Attachments
To get a list of attachments for an email, use the Get Email endpoint:Inline Attachments
Inline attachments (images embedded in HTML emails) have acontentId field:
Security
- Authentication Required: All attachment downloads require a valid API key
- User Scoping: Users can only download attachments from their own emails
- Content Validation: Filenames are URL-decoded and validated
- Binary Safety: Files are returned as-is without modification
- Private Caching: Cache-Control header set to
privateto prevent public caching
Best Practices
- Check Email First: Use the Get Email endpoint to verify attachments exist before downloading
- Handle Large Files: Implement streaming for large attachment downloads
- Validate Content-Type: Always check the Content-Type header before processing
- URL Encode Filenames: Encode special characters in filenames when constructing URLs
- Error Handling: Implement proper error handling for missing or inaccessible attachments