Overview

SendLayer allows you to send emails with file attachments. This guide shows you how to send emails with attachments using the SendLayer API, with examples for popular programming languages.

Prerequisites

Sending Emails with Attachments

You can attach files to your emails by including an attachments array in your email parameters. The SendLayer SDKs handle file encoding automatically, so you only need to provide the file path and type.
The maximum file size per email is 10 MB, including both the email content and all attachments combined.
import { SendLayer } from 'sendlayer';

const sendlayer = new SendLayer('your-api-key');

const params = {
  from: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Document Attachment',
  html: '<html><body><h1>Please find the attached document</h1><p>I have attached the requested PDF file for your review.</p></body></html>',
  attachments: [
    {
      path: './path/to/document.pdf',
      type: 'application/pdf'
    }
  ]
};

const response = await sendlayer.Emails.send(params);
Replace <apiKey> with your actual SendLayer API key in the request header. The Content field in the cURL example should contain the actual base64-encoded file content.

Multiple Attachments

You can attach multiple files to a single email by adding more objects to the attachments array.
const params = {
  from: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Multiple Attachments',
  html: '<html><body><h1>Multiple Files Attached</h1><p>Please find the attached documents.</p></body></html>',
  attachments: [
    {
      path: './path/to/document.pdf',
      type: 'application/pdf'
    },
    {
      path: './path/to/image.jpg',
      type: 'image/jpeg'
    }
  ]
};

Local and Remote File Attachments

SendLayer SDKs support both local and remote file attachments. For local files, you’ll need to provide the path to the file you intend to attach. For remote files, simply provide the URL.
const params = {
  from: 'sender@example.com',
  to: 'recipient@example.com',
  subject: 'Mixed Attachments',
  html: '<html><body><h1>Files from different sources</h1><p>Attaching both local and remote files.</p></body></html>',
  attachments: [
    {
      path: './local-document.pdf',
      type: 'application/pdf'
    },
    {
      path: 'https://example.com/remote-image.jpg',
      type: 'image/jpeg'
    }
  ]
};

Supported File Types

SendLayer supports a wide range of file types for attachments. Here are some common MIME types:
  • Documents: application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • Spreadsheets: application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • Images: image/jpeg, image/png, image/gif
  • Text Files: text/plain, text/csv
  • Archives: application/zip, application/x-rar-compressed
See our Send Email guide for basic email sending instructions.

FAQ

The maximum file size per email is 10 MB, which includes both the email content and all attachments combined. If you need to send larger files, consider using cloud storage services and including download links in your emails.
You can attach multiple files to a single email, but the total size of all attachments plus the email content must not exceed 10 MB. There is no specific limit on the number of files, only the total size limit.
SendLayer supports most common file formats including PDFs, Word documents, Excel spreadsheets, images (JPEG, PNG, GIF), text files, and compressed archives. The file type should be specified using the appropriate MIME type.
The SendLayer SDKs handle file encoding automatically. Simply provide the file path (for local files) or URL (for remote files) along with the MIME type. The SDK will read and encode the file for you.
Yes, you can attach files when sending to multiple recipients. The same attachment will be sent to all recipients in the email. See our Send Email to Multiple Recipients guide for more details.
If your attachment exceeds the 10 MB limit, consider compressing the file, using a cloud storage service and including a download link, or splitting the content into multiple emails with smaller attachments.