0

I have a Content Type Named XYZ. This content Type has a field named Email Addresses, which contains the List of Email address of the users in the Portal.

Now when the user adds the Content of XYZ and selects the desired Email Address from the Email Addresses List, the email should be sent to all the selected Email Addresses.

I know the Rules module should be used to perform this, but guide me the steps, how to make such rule?

  • Any feedback about my answer? – Pierre.Vriens Sep 5 '17 at 15:27
1

Assuming this question is about D7, you can use the Rules module to create a rule like so (in Rules export format):

{ "rules_send_email_to_selected_email_ids" : {
    "LABEL" : "Send eMail to selected eMail IDs",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : {
      "node_insert--article" : { "bundle" : "article" }
    },
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "node:field-email-addresses" ] },
          "ITEM" : { "current_email_id" : "Current eMail ID" },
          "DO" : [
            { "drupal_message" : { "message" : "An eMail about this new content with title \u0022[node:title]\u0022 and URL [node:url] will be delivered to [current-email-id:value]." } },
            { "mail" : {
                "to" : "[current-email-id:value]",
                "subject" : "You have new mail ...",
                "message" : "New content was created with title [node:title] ... You can read about it at [node:url].",
                "language" : [ "" ]
              }
            }
          ]
        }
      }
    ]
  }
}

Some more details about the above rule:

  • Rules Event: After saving new content of type "Article" (adapt the type to fit your needs, ie to XYZ).
  • Rules Action: a "loop" for all selected values of a multi value select list (contain the eMail IDs), with machine name field_email_addresses (adapt the machine name to fit your needs). For each item (= current_email_id), an eMail is created with some subject and message that also contains the title and url of the node being created. Note: this will send 1 separated eMail to each of the selected eMail IDs (there is no way to send a single eMail to all selected eMail IDs).

If you have the Rules UI enabled, you can import the above rule in your own site, after you adapt the machine names of the content type and the field name containing the list of eMail Ids.

After you're convinced the rule works as expected, you may want to remove the Rules Action that displays a message after the node is saved (with drupal_message).

Video tutorial: have a look at the List and loops video which show a similar scenario.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.