Commerce message notify sending duplicate emails I have created a custom commerce order status called 'Sent'.

When an existing order is updated from 'Invoiced' to 'Sent' I have a custom message type ('Order sent') and, using Rules, a custom rule which creates a message entity and sends the 'Order sent' message.

The rule is as follows:

{ "commerce_message_commerce_order_message_order_sent_e_mail" : {
    "LABEL" : "Commerce order message: order sent e-mail",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "3",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "message_notify", "entity" ],
    "ON" : { "commerce_order_update" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "commerce-order:status" ], "value" : "sent" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "commerce_order_order_sent",
            "param_user" : [ "commerce-order:owner" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-ds-message-commerce-order" ],
          "value" : [ "commerce-order" ]
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : "1" } },
      { "message_notify_process" : {
          "message" : [ "entity-created" ],
          "save_on_fail" : "0",
          "save_on_success" : "0"
        }
      }
    ]
  }
}


At the moment, I am receiving 3 duplicate emails and can't work out why?
It's obvious that the update event you're using in your custom rule gets triggered twice, which explains why you get those duplicate mails. I've seen similar issues in the past with other entities being updated (using similar events), for entities such as users or nodes.

If you cannot find the root cause for the duplicate trigger, and cannot use any other Rules Event as an alternative, then the typical solution is to use the Flag module like so:


Define a non-global flag to flag orders.
Add a Rules Action to your custom rule to also flag the order (for which you want to send such eMails).
Add an extra Rules Condition to check that the order is NOT (repeat: NOT!) yet flagged.


With the above tuning of your existing rule in place, the first time your rule is triggered the Rules Actions do get performed (= send the eMail and flag the order) and the second time the extra Rules Condition will prevent the Rules Actions to be performed (= no more duplicate eMail).

Easy, no? ... And it works for any entity ...