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