Download and email a file to a customer, when purchased, with Mechanic.

Mechanic is a development platform for Shopify. :)

Download and email a file to a customer, when purchased

by Isaac Bowen (team@usemechanic.com)

This task watches for newly-paid orders. When an order contains a certain line item, this task retrieves a file from the URL of your choice, and emails that file to the customer. Because URLs are easier to share, this makes for a safer way to distribute downloadable materials.

Runs when an order is paid. Configuration includes required line item title, email subject, email body, attachment filename, and attachment url.

15-day free trial – unlimited tasks

Documentation

This task watches for newly-paid orders. When an order contains a certain line item, this task retrieves a file from the URL of your choice, and emails that file to the customer. Because URLs are easier to share, this makes for a safer way to distribute downloadable materials.

Shopify allows file uploads via the "Files" page. Once uploaded, you'll receive a URL which can be used for this task. Learn how to upload files to Shopify.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

Events
when an order is paid (shopify/orders/paid)
Options
required line item title (required), email subject (required), email body (required, multiline), attachment filename (required), attachment url (required)
Script
{% if event.preview %}
  {% capture order_json %}
    {
      "line_items": [
        {
          "title": {{ options.required_line_item_title__required | json }}
        }
      ]
    }
  {% endcapture %}

  {% assign order = order_json | parse_json %}
{% endif %}

{% assign line_item_titles = order.line_items | map: "title" %}

{% if line_item_titles contains options.required_line_item_title__required %}
  {% action "email" %}
    {
      "to": {{ order.email | json }},
      "subject": {{ options.email_subject__required | json }},
      "body": {{ options.email_body__required_multiline | newline_to_br | json }},
      "reply_to": {{ shop.customer_email | json }},
      "from_display_name": {{ shop.name | json }},
      "attachments": {
        {{ options.attachment_filename__required | json }}: {
          "url": {{ options.attachment_url__required | json }}
        }
      }
    }
  {% endaction %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
Required line item title
Course
Email subject
Here's your purchased course! (Order {{ order.name }})
Email body
Hey there! Thanks for purchasing this course. You'll find the PDF attached to this email. :)

Thanks,
{{ shop.name }}
Attachment filename
Course for order {{ order.name }}.pdf
Attachment url
https://example.com/course.pdf