Skip to main content

Email Attachments

Learn how to attach files to your emails.

Basic Attachment

Attach files using base64-encoded content:
import fs from 'fs';

const fileContent = fs.readFileSync('invoice.pdf');
const base64Content = fileContent.toString('base64');

await lettr.emails.send({
  from: 'you@example.com',
  to: ['recipient@example.com'],
  subject: 'Your Invoice',
  html: '<p>Please find your invoice attached.</p>',
  attachments: [
    {
      filename: 'invoice.pdf',
      content: base64Content,
      contentType: 'application/pdf'
    }
  ]
});

Multiple Attachments

await lettr.emails.send({
  from: 'you@example.com',
  to: ['recipient@example.com'],
  subject: 'Project Files',
  html: '<p>Here are the requested files.</p>',
  attachments: [
    {
      filename: 'report.pdf',
      content: reportBase64,
      contentType: 'application/pdf'
    },
    {
      filename: 'data.xlsx',
      content: excelBase64,
      contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    },
    {
      filename: 'image.png',
      content: imageBase64,
      contentType: 'image/png'
    }
  ]
});

URL-Based Attachments

Attach files from a URL (Lettr will fetch and attach them):
await lettr.emails.send({
  from: 'you@example.com',
  to: ['recipient@example.com'],
  subject: 'Your Document',
  html: '<p>Document attached.</p>',
  attachments: [
    {
      filename: 'document.pdf',
      url: 'https://example.com/files/document.pdf'
    }
  ]
});

Inline Images

Embed images directly in your email HTML:
await lettr.emails.send({
  from: 'you@example.com',
  to: ['recipient@example.com'],
  subject: 'Email with Image',
  html: '<p>Check out this image:</p><img src="cid:logo" />',
  attachments: [
    {
      filename: 'logo.png',
      content: logoBase64,
      contentType: 'image/png',
      cid: 'logo' // Content-ID for inline reference
    }
  ]
});

Attachment Limits

LimitValue
Max attachment size25 MB
Max total email size30 MB
Max attachments per email10
Large attachments can affect deliverability and may be blocked by recipient email servers. Consider using download links for files over 10 MB.

Common MIME Types

ExtensionMIME Type
.pdfapplication/pdf
.docapplication/msword
.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
.xlsapplication/vnd.ms-excel
.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.pngimage/png
.jpgimage/jpeg
.gifimage/gif
.zipapplication/zip
.csvtext/csv