Adding Attachments to Emails

MailerSend allows you to attach files to your emails to provide additional information or context for your recipients.

In this guide, we'll walk you through the process of adding attachments to your emails using cURL calls. You can also use any of our SDKs.

What do I need?

  • MailerSend account
  • Add and verify at least one sending domain
  • Generate an API token
  • Ensure you have cURL installed on your machine

How do I add attachments to my email?

Here’s an example request using cURL

curl --request POST \
  --url https://api.mailersend.com/v1/email \
  --header 'Authorization: Bearer API_KEY_HERE' \
  --header 'Content-Type: application/json' \
  --data '{
      "to": [
        {
          "email": "recipient@email.com"
        }
      ],
      "from": {
        "email": "your@email.com"
      },
      "subject": "New Attachment Test",
      "html": "<p>Hello world!</p>",
      "attachments": [
        {
          "filename": "attachment.jpg",
          "content": "BASE64_ENCODED_CONTENT_HERE"
        }
      ]
    }'
  • Copy and paste the cURL command into your terminal
  • Replace from , to , API_KEY_HERE and BASE64_ENCODED_CONTENT_HERE with your values
  • Press the enter key

Note:

  • The attachments array includes information about the file you want to attach, such as the filename, and base64-encoded content
  • You can also pass "disposition": "inline" | "attachment" to the attachment object. Use inline to make it accessible for content. Use attachment for normal attachments
  • Attachment size cannot be more than 25MB after decoding
  • You can encode files using online services such as Base64 guruopen in new window or Base64 Encodeopen in new window

Congratulations! You've now sent an email with an attachment via MailerSend's API using cURL.

We're excited to have you on board and look forward to helping you integrate our service seamlessly into your application. If you have any questions or encounter any issues, don't hesitate to reach out to our support team for assistance.

What’s next?

Last Updated: