Send email alerts by event topic, with Mechanic.

Mechanic is a development platform for Shopify. :)

Send email alerts by event topic

This task allows you to receive an email alert for any event topic supported by Mechanic. Configure the task with a list of email addresses to notify, an email subject, and one or more event topics, each paired with an email body that supports liquid output tags for the main object of each event (e.g. shopify/products/create can use attributes like {{ product.id }} or {{ product.title }})

Runs when a product is created and when a customer is created. Configuration includes emails to notify, general email subject, append event topic to email subject, and event topics and email bodies.

15-day free trial – unlimited tasks

Documentation

This task allows you to receive an email alert for any event topic supported by Mechanic. Configure the task with a list of email addresses to notify, an email subject, and one or more event topics, each paired with an email body that supports liquid output tags for the main object of each event (e.g. shopify/products/create can use attributes like {{ product.id }} or {{ product.title }})

The task comes preloaded with the customers and products create event topics, along with sample email bodies. Configure to taste :) The full list of supported event topics can be found here.

Note:
- The task will replace the OBJECT_LINK string within the email body if present (and where it makes sense to do so) with an admin link to the Shopify object related to the event topic.
- Some event topics, like shopify/products/update and shopify/inventory_levels/update, can generate a lot of emails, so they should be used with caution.
- When using the shopify/orders/edited event topic, the original order can be referenced using {{ order_edit.order }}.

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.

Open source
View on GitHub to contribute to this task
Events
when a product is created (shopify/products/create)
when a customer is created (shopify/customers/create)
Options
emails to notify (array, required), general email subject (required), append event topic to email subject (boolean), event topics and email bodies (keyval, multiline, required)
Script
{% comment %}
  Preferred option order:

  {{ options.emails_to_notify__array_required }}
  {{ options.general_email_subject__required }}
  {{ options.append_event_topic_to_email_subject__boolean }}
  {{ options.event_topics_and_email_bodies__keyval_multiline_required }}
{% endcomment %}

{% assign email_recipients = options.emails_to_notify__array_required %}

{% for keyval in options.event_topics_and_email_bodies__keyval_multiline_required %}
  {% assign configured_event_topic = keyval.first %}

  {% if event.topic == configured_event_topic %}
    {% assign email_subject = options.general_email_subject__required %}
    {% assign email_body = keyval.last %}

    {% if options.append_event_topic_to_email_subject__boolean %}
      {% assign email_subject = email_subject | append: " [" | append: configured_event_topic | append: "]" %}
    {% endif %}

    {% capture admin_link %}https://{{ shop.myshopify_domain }}/admin/{% endcapture %}

    {% assign object_link = nil %}

    {% if event.topic contains "shopify/collections/" %}
      {% capture object_link %}collections/{{ collection.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/customers/" %}
      {% capture object_link %}customers/{{ customer.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/draft_orders/" %}
      {% capture object_link %}draft_orders/{{ draft_order.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/fulfillment_events/" %}
      {% capture object_link %}orders/{{ fulfillment_event.order.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/fulfillments/" %}
      {% capture object_link %}orders/{{ fulfillment.order.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/orders/" %}
      {% capture object_link %}orders/{{ order.id | default: order_edit.order.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/products/" %}
      {% capture object_link %}products/{{ product.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/refunds/" %}
      {% capture object_link %}orders/{{ refund.order.id | default: 1234567890 }}{% endcapture %}

    {% elsif event.topic contains "shopify/themes/" %}
      {% capture object_link %}themes/{{ theme.id | default: 1234567890 }}{% endcapture %}
    {% endif%}

    {% if object_link != blank %}
      {% assign object_link = admin_link | append: object_link %}
    {% else %}
      {% assign object_link = "[<small>Object link could not be generated</small>]" %}
    {% endif %}

    {% assign email_body = email_body | replace: "OBJECT_LINK", object_link %}

    {% action "email" %}
      {
        "to": {{ email_recipients | join: ", " | json }},
        "subject": {{ email_subject | json }},
        "body": {{ email_body | unindent | newline_to_br | json }},
        "from_display_name": {{ shop.name | json }}
      }
    {% endaction %}
  {% endif %}
{% endfor %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.
Defaults
General email subject
ALERT
Append event topic to email subject
true
Event topics and email bodies
{"shopify/products/create"=>"Hi,\n\nProduct {{ product.id }} was created\n\nView the details in Shopify:\nOBJECT_LINK", "shopify/customers/create"=>"Hi\n\nCustomer {{ customer.id }} was created\n\nView the details in Shopify:\nOBJECT_LINK"}