Skip to main content

Overview

Attachments allow you to send and receive files with your emails. Jasni supports all common file types and provides metadata about attachments when listing or reading emails.

Attachment Structure

When you read an email, attachment metadata is included:
FieldTypeDescription
filenamestringOriginal filename
contentTypestringMIME type (e.g., application/pdf)
sizeintegerFile size in bytes
contentIdstringContent-ID for inline attachments

Example Response

{
  "uid": 123,
  "subject": "Monthly Report",
  "attachments": [
    {
      "filename": "report.pdf",
      "contentType": "application/pdf",
      "size": 245678
    },
    {
      "filename": "data.xlsx",
      "contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
      "size": 89432
    }
  ]
}

Sending Attachments

Include attachments when sending an email:
POST /api/v1/emails/send
{
  "from": "[email protected]",
  "to": ["[email protected]"],
  "subject": "Document attached",
  "text": "Please find the document attached.",
  "attachments": [
    {
      "filename": "document.pdf",
      "content": "base64_encoded_content_here",
      "contentType": "application/pdf"
    }
  ]
}
Attachment content must be base64 encoded. Most SDKs handle this automatically.

Supported File Types

Jasni supports all standard MIME types:
CategoryCommon Types
DocumentsPDF, DOC, DOCX, XLS, XLSX, PPT, PPTX
ImagesPNG, JPG, GIF, SVG, WEBP
ArchivesZIP, RAR, 7Z, TAR, GZ
TextTXT, CSV, JSON, XML, HTML
MediaMP3, MP4, WAV, MOV

Size Limits

LimitValue
Single attachment25 MB
Total per email25 MB
For larger files, consider using a file sharing service and including a link in the email.

Inline Attachments

Inline attachments (like images embedded in HTML) use the contentId field:
{
  "html": "<p>See the image below:</p><img src=\"cid:logo123\">",
  "attachments": [
    {
      "filename": "logo.png",
      "content": "base64_encoded_content",
      "contentType": "image/png",
      "contentId": "logo123"
    }
  ]
}
The cid: prefix in the HTML references the contentId of the attachment.

Working with Attachments in SDKs

TypeScript SDK

import { Jasni } from 'jasni-sdk'
import { readFileSync } from 'fs'

const jasni = new Jasni('jsk_your_api_key')

// Read file and convert to base64
const fileBuffer = readFileSync('./document.pdf')
const base64Content = fileBuffer.toString('base64')

await jasni.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Document attached',
  text: 'Please find the document attached.',
  attachments: [
    {
      filename: 'document.pdf',
      content: base64Content,
      contentType: 'application/pdf'
    }
  ]
})

Python SDK

from jasni import Jasni
import base64

jasni = Jasni('jsk_your_api_key')

# Read file and convert to base64
with open('document.pdf', 'rb') as f:
    content = base64.b64encode(f.read()).decode('utf-8')

jasni.emails.send(
    from_='[email protected]',
    to='[email protected]',
    subject='Document attached',
    text='Please find the document attached.',
    attachments=[
        {
            'filename': 'document.pdf',
            'content': content,
            'contentType': 'application/pdf'
        }
    ]
)

Best Practices

Check file types before processing attachments to avoid security risks.
If accepting attachments from external sources, consider scanning them for malware.
Give attachments clear, descriptive names so recipients know what they’re downloading.
For multiple files, consider compressing them into a single ZIP archive.