> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Attachments Canonical URL: https://posthog.com/docs/workflows/transactional/attachments > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.posthog.com` instead of `https://us.posthog.com` (app host for links). ## On this page - [Attach files](#attach-files) - [Send files with the API](#send-files-with-the-api) - [Errors](#errors) Emails that you [send from code](https://posthog.com/docs/workflows/transactional/send-from-code.md#send-the-html) can carry files, such as a PDF receipt or a calendar invite. A template send can't. To send attachments, [verify your domain](https://posthog.com/docs/workflows/domain.md) first. The [test sender](https://posthog.com/docs/workflows/email/test-sender.md) doesn't send them. Ask your agentwith the [PostHog MCP](https://posthog.com/docs/workflows/mcp.md)[sending-transactional-emails](https://posthog.com/docs/workflows/skills.md) “Update our receipt email send to attach the generated PDF invoice using the PostHog SDK.” Copy ## 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. ### Node.js ```javascript await posthog.emails.send({ to: "ada@example.com", templateKey: "receipt", subject: "Your receipt for order 1042", html, attachments: [{ filename: "invoice-1042.pdf", content: pdfBytes, contentType: "application/pdf" }], idempotencyKey: "receipt-1042", }) ``` ### Python ```python posthog.emails.send( to="ada@example.com", template_key="receipt", subject="Your receipt for order 1042", html=html, attachments=[{"filename": "invoice-1042.pdf", "content": pdf_bytes, "content_type": "application/pdf"}], idempotency_key="receipt-1042", ) ``` ### Ruby ```ruby $posthog.emails.send( to: 'ada@example.com', template_key: 'receipt', subject: 'Your receipt for order 1042', html: html, attachments: [{ filename: 'invoice-1042.pdf', content: File.binread(pdf_path), content_type: 'application/pdf' }], idempotency_key: 'receipt-1042' ) ``` ### Rust ```rust posthog .emails() .send( CodeEmail::new("ada@example.com", "receipt", "Your receipt for order 1042") .html(html) // Call attachment once for each file .attachment(EmailAttachment::new("invoice-1042.pdf", pdf_bytes).content_type("application/pdf")) .idempotency_key("receipt-1042"), ) .await?; ``` ### PHP ```php PostHog::emails()->send([ 'to' => 'ada@example.com', 'template_key' => 'receipt', 'subject' => 'Your receipt for order 1042', 'html' => $html, 'attachments' => [ ['filename' => 'invoice-1042.pdf', 'content' => file_get_contents($pdfPath), 'content_type' => 'application/pdf'], ], 'idempotency_key' => 'receipt-1042', ]); ``` ### Go ```go _, err := client.Emails().Send(ctx, posthog.CodeEmail{ To: "ada@example.com", TemplateKey: "receipt", Subject: "Your receipt for order 1042", HTML: html, Attachments: []posthog.EmailAttachment{ {Filename: "invoice-1042.pdf", Content: pdfBytes, ContentType: "application/pdf"}, }, IdempotencyKey: "receipt-1042", }) ``` ### .NET ```csharp await emails.SendAsync(new SendCodeEmailOptions { To = "ada@example.com", TemplateKey = "receipt", Subject = "Your receipt for order 1042", Html = html, Attachments = [ new EmailAttachment { Filename = "invoice-1042.pdf", Content = pdfBytes, ContentType = "application/pdf" }, ], IdempotencyKey = "receipt-1042", }); ``` ### Elixir ```elixir PostHog.Emails.send( to: "ada@example.com", template_key: "receipt", subject: "Your receipt for order 1042", html: html, attachments: [%{filename: "invoice-1042.pdf", content: pdf_bytes, content_type: "application/pdf"}], idempotency_key: "receipt-1042" ) ``` ### REST ```bash # Upload the file first (see "Send files with the API" below), then send its sha256 and filename curl -X POST "https://us.posthog.com/api/messaging/send/email/" \ -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: receipt-1042" \ -d '{"to": "ada@example.com", "template_key": "receipt", "subject": "Your receipt for order 1042", "html": "
Your invoice is attached.
", "attachments": [{"sha256": "d00ca3c2296eace098658a8576dafec8a959f5da536a51c8f9d060c00e427252", "filename": "invoice-1042.pdf", "content_type": "application/pdf"}]}' ``` - **Limits:** 10 files, and 40 MB per email after Base64 encoding, which is about 29 MB of files. See [API and SDK limits](https://posthog.com/docs/workflows/reference/limits.md#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 `