EnvlopedDocs

Attachments

Send file attachments with your emails

Attachments

Send file attachments (PDFs, calendar invites, images, etc.) alongside your emails.

Overview

The attachments field accepts an array of file objects. Each file must be base64-encoded. No raw MIME construction needed.

Limits

ConstraintLimit
Max attachments per email10
Max total attachment size40 MB (decoded)

Attachment Object

FieldTypeRequiredDescription
filenamestringYesThe filename shown to the recipient (e.g. "report.pdf").
contentstringYesBase64-encoded file content.
contentTypestringNoMIME type. Examples: "application/pdf", "text/calendar", "image/png".

Examples

cURL — Calendar Invite

# Base64-encode your file
ICS_BASE64=$(base64 -i invite.ics)

curl -X POST https://api.envloped.com/v1/emails \
  -H "Authorization: Bearer en_abc123..." \
  -H "Content-Type: application/json" \
  -d "{
    \"from\": \"Your App <hello@yourdomain.com>\",
    \"to\": \"user@example.com\",
    \"subject\": \"Meeting Invite\",
    \"html\": \"<p>See the attached calendar invite.</p>\",
    \"attachments\": [{
      \"filename\": \"invite.ics\",
      \"content\": \"$ICS_BASE64\",
      \"contentType\": \"text/calendar\"
    }]
  }"

JavaScript / TypeScript (SDK)

import { EnvlopedClient } from '@envloped/envloped-js';
import { readFileSync } from 'fs';

const client = new EnvlopedClient({ apiKey: 'en_abc123...' });

const pdfBase64 = readFileSync('report.pdf').toString('base64');

await client.emails.send({
  from: 'Your App <hello@yourdomain.com>',
  to: ['user@example.com'],
  subject: 'Monthly Report',
  html: '<p>Please find the report attached.</p>',
  attachments: [
    {
      filename: 'report.pdf',
      content: pdfBase64,
      contentType: 'application/pdf',
    },
  ],
});

Go (SDK)

import (
    "encoding/base64"
    "os"

    envloped "github.com/envloped/envloped-go"
)

client := envloped.NewClient("en_abc123...")

data, _ := os.ReadFile("invite.ics")
encoded := base64.StdEncoding.EncodeToString(data)

resp, err := client.Emails.Send(&envloped.SendEmailRequest{
    From:    "Your App <hello@yourdomain.com>",
    To:      []string{"user@example.com"},
    Subject: "Meeting Invite",
    Html:    "<p>See the attached calendar invite.</p>",
    Attachments: []envloped.Attachment{
        {
            Filename:    "invite.ics",
            Content:     encoded,
            ContentType: "text/calendar",
        },
    },
})

Python

import base64
import os
import requests

with open("report.pdf", "rb") as f:
    pdf_base64 = base64.b64encode(f.read()).decode("utf-8")

response = requests.post(
    "https://api.envloped.com/v1/emails",
    headers={
        "Authorization": f"Bearer {os.environ['ENVLOPED_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "from": "Your App <hello@yourdomain.com>",
        "to": "user@example.com",
        "subject": "Monthly Report",
        "html": "<p>Please find the report attached.</p>",
        "attachments": [
            {
                "filename": "report.pdf",
                "content": pdf_base64,
                "contentType": "application/pdf",
            }
        ],
    },
)

Multiple Attachments

{
  "from": "hello@yourdomain.com",
  "to": "user@example.com",
  "subject": "Your order confirmation",
  "html": "<p>Receipt and calendar invite attached.</p>",
  "attachments": [
    {
      "filename": "receipt.pdf",
      "content": "JVBERi0xLjQ...",
      "contentType": "application/pdf"
    },
    {
      "filename": "delivery.ics",
      "content": "QkVHSU46VkNB...",
      "contentType": "text/calendar"
    }
  ]
}

Error Responses

Missing filename

{ "error": "Each attachment must have a filename" }

Missing content

{ "error": "Each attachment must have base64-encoded content" }

Too many attachments

{ "error": "Maximum 10 attachments allowed" }

Total size exceeded

{ "error": "Total attachment size must not exceed 40MB" }

On this page