Adding Attachments to an Email Notification

Last edit: Jun 10, 2019
  • Contributors:
  • pavelloz

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 notifications/email_notifications/welcome_user.liquid created in a previous tutorial:


---
name: welcome_user
to: '{{ form.email }}'
enabled: true
trigger_condition: true
from: 'Example Marketplace <info@example.com>'
reply_to: no-reply@example.com
subject: 'Welcome {{ form.first_name }} in our marketplace!'
layout_path: 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 as inline:

{
 "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.