Email customers when tagged with Mechanic.

Mechanic is the one-tool-does-it-all automation app for Shopify. :)

Email customers when tagged

by Isaac Bowen (team@usemechanic.com)

Automatically send out an email to your customers when a tag is added to their account. Useful for sending approval emails, welcome emails if the customer was created with a certain tag, or any other emails related to an update to the customer's status.

Runs when a customer is created and when a customer is updated. Configuration includes tag to watch for, email subject, and email body.

15-day free trial – unlimited tasks

Documentation

This task monitors customer updates and new customer registrations, looking for the tag of your choice. When a customer record is created with that tag, or has that tag added to it, this task will send the customer an email.

The most common use of this task is to send out emails to customers when their accounts are approved, but you can use this task to email customers any kind of alert you like, triggered by a simple tag. For example, some themes include an email subscription form that creates a customer record, pre-tagged with "email subscribe", or something to that effect.

Important notes:

  • This task also adds a second tag when the email is sent, as a flag to mark the customer as having received that email. This helps Mechanic remember who not to send an email to.
  • To help out merchants who have lots of existing customers, this task doesn't watch customers whose records were created before you add this task to your Mechanic account.

Developer details

Events
when a customer is created (shopify/customers/create)
when a customer is updated (shopify/customers/update)
Options
tag to watch for (required), email subject (required), email body (required, multiline)
Script
{% assign approval_tag = options.tag_to_watch_for__required %}
{% capture email_sent_tag %}{{ approval_tag }}-email-sent{% endcapture %}
{% assign customer_tags = customer.tags | split: ", " %}

{% assign customer_qualifies = false %}
{% assign customer_created_at = customer.created_at | date: "%s" %}
{% assign task_created_at = task.created_at | date: "%s" %}
{% if customer_tags contains approval_tag and customer_created_at >= task_created_at %}
  {% unless customer_tags contains email_sent_tag %}
    {% assign customer_qualifies = true %}
  {% endunless %}
{% endif %}

{% if event.preview or customer_qualifies %}
  {
    "action": {
      "type": "email",
      "options": {
        "to": {{ customer.email | json }},
        "subject": {{ options.email_subject__required | json }},
        "body": {{ options.email_body__required_multiline | strip | newline_to_br | json }},
        "reply_to": {{ shop.customer_email | json }},
        "from_display_name": {{ shop.name | json }}
      }
    }
  }

  {% capture tags_to_save %}{{ customer.tags }}, {{ email_sent_tag }}{% endcapture %}

  {
    "action": {
      "type": "shopify",
      "options": [
        "update",
        [
          "customer",
          {{ customer.id | json }}
        ],
        {
          "tags": {{ tags_to_save | json }}
        }
      ]
    }
  }
{% endif %}
Yep, that’s just Liquid! If this is interesting to you, check out our documentation! Mechanic is hugely developer-friendly. :)
Defaults
Tag to watch for
approved
Email subject
Your account has been approved!
Email body
Hi {{ customer.first_name | default: "there" }},

Your account for {{ shop.name }} has been approved! Thanks for registering, and we'll see you soon.

Thanks,
The team at {{ shop.name }}