Mechanic Get Mechanic
Task library

Download and email a file to a customer, when purchased

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.

Try this task

When it runs

Occurs whenever an order is paid

What you choose

  • Required line item title
  • Email subject
  • Email body
  • Attachment filename
  • Attachment URL

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.

Task code and subscriptions

You can edit the Liquid code after installing this task. View on GitHub or ask a question in the Mechanic Slack community.

Subscriptions

shopify/orders/paid
How task subscriptions work

Option types and flags

Task code

{% 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 Liquid reference

Default option values

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