# Win back shoppers with marketing emails

> Turn on the emails your store sends when a shopper leaves a cart, a payment fails or an order ships, add discount codes, and manage who gets none.

Source: https://www.coritan.com/docs/organizations/commerce/marketing/

In the dashboard:

- /dashboard/organizations/…/commerce/marketing: https://www.coritan.com/dashboard/organizations

**Marketing** holds the store's flows: emails the store sends on its own when something happens to a shopper's cart or order. There are three. The abandoned cart flow reminds a shopper who left items in a cart, the failed payment flow writes when a payment is declined, and the restock flow asks a shopper to order again some days after their order shipped. Every flow is off until you turn it on.

Every flow email carries an unsubscribe link. A shopper who uses it goes on the store's **Suppression list**, and no flow emails them again. Order and shipping emails still reach them.

## Before you begin

- Everyone who can open the Commerce tab sees the flows. You need the Admin role to change a flow or send a test, Tier 1 support or higher to read the message log and the suppression list, and Tier 3 support or higher to add or remove an address.
- Set the **Storefront address** in [Settings](/docs/organizations/commerce/settings/#storefront-settings). The emails link to the shopper's cart and to the unsubscribe page on your storefront. Without the address, the abandoned cart and failed payment emails have no cart link, and the unsubscribe link opens a Coritan page instead.
- Your storefront needs two pages for those links: `/cart/recover`, which opens the cart, and `/unsubscribe`, which takes the shopper off the list. [Build a checkout with the Store API](/docs/organizations/storefront/store-api/#answer-the-links-in-flow-emails) shows both.
- To give a discount code in an email, create a promotion with a code first in [Discounts](/docs/organizations/commerce/discounts/). Each email then gets a code of its own, made from that promotion.

## The three flows

**Abandoned cart**
: Starts when a cart that has items and an email address has not changed for the time set in **A cart counts as abandoned after**, from 5 to 1,440 minutes. It sends up to five emails, each after its own wait. Every wait counts from the shopper's last change to the cart, so a shopper who comes back and changes the cart starts the unsent emails again from that moment. An email that has gone out is never sent twice.

**Failed payment**
: Sends one email after a shopper's payment is declined or fails at checkout, after the wait set in **Send after the failure**. The email links back to the cart so the shopper can try again.

**Restock**
: Sends one email per order, a set number of days after the order's first parcel shipped, from 1 to 365. It counts orders that ship after you turn it on.

When a cart is checked out, emptied or expires, its scheduled emails are cancelled. When an order is cancelled, its restock email is skipped.

## Turn on a flow

1. In the [dashboard](https://www.coritan.com/dashboard/organizations), open the organization, then **Commerce**, then **Marketing**.
2. On the flow's card, turn on its switch.
3. Set its timings. For the abandoned cart flow, select **Add email** to add a reminder, up to five, or select the bin beside one to remove it. Each email must wait longer than the one before it.
4. Choose a **Discount code** for any email that should carry one, as in the next section.
5. Select **Save changes**. **Discard** puts the card back as it was saved.

The flow starts on its next run, within a minute. It does not write to shoppers about carts that were already idle for more than a day when you turned it on: an email more than a day late is skipped, not sent.

## Give a discount code in an email

In **Discount code**, choose one of the store's promotions, then set **Code works for** in hours, from 1 to 720. When the email is sent, the store makes a single use code from that promotion and puts it in the email. The code works only for the address it was sent to, and only for that many hours.

Only promotions with a code can be chosen, and not the codes other emails already made. If the promotion is deleted later, the email goes without a code and the message log says so.

## Try a flow before going live

**Send a test to me** sends the flow's email to your own address, with sample products, a sample code and the subject starting `[TEST]`. For the abandoned cart flow, choose which email to send. You can send 10 tests an hour. A test makes no code and does not appear in the message log.

Carts and orders made with a test publishable key get no flow email. To try the flows end to end in test mode, turn on **Email test carts and orders** in the **Flows** card. Test emails carry the `[TEST]` subject start too. Turn it off again before going live.

## Read the message log

**Messages** lists every email the flows scheduled, newest first, with the shopper's address, the email it is, its status, the cart or order it is about, the code it carried and when it was due or sent. Filter it by flow, by status and by part of an address. The filters are kept in the page address, so a reload or a shared link opens the same list.

| Status | What it means |
| --- | --- |
| Scheduled | The email waits for its time. |
| Sent | The email went out. |
| Skipped | The email was due but not sent. The row says why: the address is on the suppression list, the cart was checked out, the flow was turned off, or the email was more than a day late. |
| Failed | The email could not be sent. It is not tried again. |
| Cancelled | The cart was checked out, emptied or expired before the email was due. |

## Keep an address off the flows

The **Suppression list** holds the addresses no flow emails. An address lands there when a shopper unsubscribes, and you can add one yourself.

To add an address:

1. Select **Add address…**.
2. Enter the email address and select **Add address**.

To take an address off the list:

1. Select the address's actions menu, then **Remove from the list…**.
2. The dialog names the address. Select **Remove address**.

The flows email that address again from their next run. Search the list by part of an address, or filter it by reason. Each change is recorded in the organization's audit log.

## How unsubscribing works

Each flow email has an unsubscribe link at its foot and the `List-Unsubscribe` and `List-Unsubscribe-Post` headers, so mail apps that offer their own unsubscribe button can use it. Either way the address goes on the list at once, with the reason **Unsubscribed**. The link never expires, and it works only for your store.

Opening the link does not unsubscribe by itself. The page asks the shopper to confirm, so a mail scanner that follows links cannot take a shopper off your emails.

## Result

- A flow that is on schedules its emails within a minute of a cart or order qualifying, and **Messages** lists each one.
- A shopper who unsubscribes gets no further flow email, and their scheduled emails are cancelled. An address you add gets none either: its scheduled emails are skipped when they come due.

## Troubleshooting

A flow is on but **Messages** stays empty
: The cart has no email address, has no items, or has not been idle long enough. Test carts send nothing unless **Email test carts and orders** is on. The store must be live or in test mode, not suspended.

The emails have no link to the cart
: The store has no **Storefront address**. Set it in [Settings](/docs/organizations/commerce/settings/#storefront-settings).

**Save changes** reports that a promotion cannot be used
: The promotion belongs to another store, or it is a code another email made. Choose one of the store's own promotions.

**Send a test to me** says to try again later
: You sent 10 tests in the last hour.

The flow cards cannot be changed
: Changing a flow needs the Admin role.

## Related

- [Create promotions and issue gift cards](/docs/organizations/commerce/discounts/)
- [Write the emails your store sends](/docs/organizations/commerce/emails/)
- [Build a checkout with the Store API](/docs/organizations/storefront/store-api/)

## With the API

`GET https://api.coritan.com/api/v1/orgs/{org_slug}/commerce/flows` answers the `flows` setting with every default filled in. Change it with `PATCH /commerce/store` and `{"settings": {"flows": {...}}}`, which replaces the whole setting. `GET /commerce/flows/messages` lists the messages with the filters `flow`, `status` and `email`, and `POST /commerce/flows/{flow}/test` sends a test to the member calling it; an API key cannot send one. `GET`, `POST` and `DELETE /commerce/email-suppressions` read and change the suppression list.

```bash
curl -X PATCH "https://api.coritan.com/api/v1/orgs/acme/commerce/store" \
  -H "Authorization: Bearer $CORITAN_TOKEN" -H "Content-Type: application/json" \
  -d '{"settings": {"flows": {"abandoned_cart": {"enabled": true, "idle_minutes": 30,
       "steps": [{"delay_minutes": 60, "code": null},
                 {"delay_minutes": 1440, "code": {"promotion_id": 12, "valid_hours": 48}}]}}}}'
```

## API

- `GET /api/v1/orgs/{org_slug}/commerce/flows`: The flows setting with every default filled in, and each flow email's name (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-get-api-v1-orgs-org-slug-commerce-flows)
- `GET /api/v1/orgs/{org_slug}/commerce/flows/messages`: List messages (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-get-api-v1-orgs-org-slug-commerce-flows-messages)
- `POST /api/v1/orgs/{org_slug}/commerce/flows/{flow}/test`: Send the flow's email to the calling member, with sample data and a sample code (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-post-api-v1-orgs-org-slug-commerce-flows-flow-test)
- `GET /api/v1/orgs/{org_slug}/commerce/email-suppressions`: The addresses no marketing email goes to, newest first (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-get-api-v1-orgs-org-slug-commerce-email-suppressions)
- `POST /api/v1/orgs/{org_slug}/commerce/email-suppressions`: Add an address by hand (reason manual) (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-post-api-v1-orgs-org-slug-commerce-email-suppressions)
- `DELETE /api/v1/orgs/{org_slug}/commerce/email-suppressions/{suppression_id}`: Take an address off the list; the flows email it again (https://www.coritan.com/docs/api/reference/organizations/commerce/commerce/#op-delete-api-v1-orgs-org-slug-commerce-email-suppressions-suppression-id)
