Homepage

Adding Attachments to an Email Notification

Last edit: Oct 26, 2022

This guide will help you attach files to an Email Notification.

Requirements

To follow the steps in this tutorial, you should understand the concept of Email Notifications. You'll use the Email Notification you created in a previous tutorial.

Steps

Attaching a file to an Email Notification is a one-step process:

Step 1: Include attachments JSON in Email Notification

Add the attachments JSON to the Email Notification created in a previous tutorial:

app/emails/welcome_user.liquid

---
to: '{{ form.email }}'
from: 'Example Marketplace <[email protected]>'
reply_to: [email protected]
subject: 'Welcome {{ form.first_name }} in our marketplace!'
layout: mailer
attachments: >
  {
    "logo.jpg": {
      "url": "https://uploads.prod01.oregon.platform-os.com/instances/1/assets/images/svg/platformos-logo.svg"
    }
  }
---
<h1>Hi {{ form.first_name }}!</h1>

<p>Welcome in our marketplace!</p>

Now, when you send an email, the attachment will be included.

You can use liquid in the attachments field, as long as it evaluates to valid JSON. The expected JSON is in the following format:

{
 "<file_name_user_will_see1>": {
   "url": "<url to the attachment>"
 },
 "<file_name_user_will_see2>": {
   "url": "<another url to the attachment>"
 }
}

You can also mark any attachment's Content-Disposition as inline.
Inline attachment means that some types of files will be displayed inside the email content by some email clients.
By default, attachments have Content-Disposition set to attachment, which means they are only available to download in email clients.

{
 "my_file": {
   "url": "<url to the attachment>",
   "inline": "true"
 }

Note

You can include up to 9 attachments, and the total size cannot exceed 20MB.

Next steps

Congratulations! You have sent an Email Notification with an attachment. Now you can learn about creating an SMS Notification.

Questions?

We are always happy to help with any questions you may have.

contact us