Attachments
Emails that you send from code can carry files, such as a PDF receipt or a calendar invite. A template send can't. To send attachments, verify your domain first. The test sender doesn't send them.
Attach files
Give the SDK each file's bytes and name. It hashes, uploads, and attaches the file. A file PostHog already has, such as your terms, isn't uploaded again.
- Limits: 10 files, and 40 MB per email after Base64 encoding, which is about 29 MB of files. See API and SDK limits for every limit on a send.
- Inline images: give the file a content ID, such as
logo, and use it in the HTML as<img src="cid:logo">. - Calendar invites: send
text/calendar; method=REQUESTas the content type, so mail apps show the file as an invite. - Blocked files: PostHog refuses types that mailbox providers block, such as
.exe. - Viruses: if the email provider finds a virus, the email fails with the reason
provider_rejected.
Send files with the API
Files go to PostHog before the email:
- Hash each file: its SHA-256, as 64 lowercase hex characters, and its size in bytes.
- Ask where to upload:
POST /api/messaging/attachments/uploads/with thefilesfor this email. PostHog answerspresentfor a file it already has, anduploadwith a URL for the rest. - Upload:
PUTeachuploadfile's bytes to its URL, with the headers exactly as given, within 15 minutes. Don't send your PostHog key. - Send: list each file's
sha256andfilenameinattachments.
Uploads go to Amazon S3. If your network limits outgoing traffic, allow hosts that end in .s3.us-east-1.amazonaws.com (US) or .s3.eu-central-1.amazonaws.com (EU). The SDKs upload the same way.
The receipt with a PDF example is a complete script.
Errors
| Code | Cause | Fix |
|---|---|---|
too_many_attachments | More than 10 files. | Link to the rest from the email. |
message_too_large | Over 40 MB after encoding. | Send fewer or smaller files, or link to them. |
attachment_not_uploaded | PostHog has no file with this hash. The upload didn't finish or expired. | Ask where to upload again, upload, and resend. |
blocked_file_type | Mailbox providers block this type. | Send another type, or link to it. |
unsafe_filename | filename has a path or a line break. | Send only the name, such as invoice.pdf. |
not_mime_type | content_type isn't a MIME type, or it has a name parameter. | Send a type such as application/pdf, or leave it out. |
unsafe_content_id | The content ID has <, >, or a line break. | Send only the ID, such as logo. |
upload_quota_exceeded | Your project hit today's upload limit. Resets at midnight UTC. | Reuse files PostHog already has, or link to new ones. |
field_not_accepted | Your project can't send files yet. | Send without files. |
Other problems with a file, such as a hash that isn't 64 lowercase hex characters, return invalid_request, and attr names the field. Each of these errors returns 400, except upload_quota_exceeded, which returns 429. PostHog sends nothing when a check fails.





