How to: Admin flags content, owners of content gets email nofication I'm building a site where users of the role Contributor submits content (songs). Songs gets rated by users of the role Curator and the best rated Songs are added to Playlists by the Admin. 

The Admin is presented with the best rated tracks in a Views table. I'd like to have a flag on each Song with these values:


Playlist add confirmed
Playlist add pending (default mode)


When admin flags the Song with the 'Playlist add confirmed' mode this should fire an email (via rules?) to the Contributor who submitted the Song in mention notifying the Contributor of the good news.

The admin table of best rated tracks are ready and working but I'm stuck at getting the Flags and email notifications working.

How would you do this?
Part 1 - Rules Component to send an eMail

Here is a Rules Component (in Rules export format) to send an eMail to a user indicated as a parameter of the Rules Component (adapt the subject and eMail body to your own needs):

{ "rules_send_email_notification" : {
    "LABEL" : "Send eMail notification",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "user_to_notify" : { "label" : "User to be notified", "type" : "user" } },
    "ACTION SET" : [
      { "mail" : {
          "to" : [ "user-to-notify:mail" ],
          "subject" : "Your eMail subject goes here ...",
          "message" : "Your message body goes here ...",
          "from" : "[site:mail]",
          "language" : [ "" ]
        }
      }
    ]
  }
}


Part 2 - Rule to trigger the Rules Component

Here is the rule (in Rules export format) to execute the Rules Component from Part 1 (adapt the machine name of the flag you're using prior to importing it in your own site):

{ "rules_send_email_to_author_of_a_flagged_node" : {
    "LABEL" : "Send eMail to author of a flagged node",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "flag" ],
    "ON" : { "flag_flagged_playlist_confirmation" : [] },
    "DO" : [
      { "component_rules_send_email_notification" : { "user_to_notify" : [ "flagged-node:author" ] } }
    ]
  }
}


This rule gets triggered (Rules Event) when a node is flagged with a flag that has machine name playlist_confirmation. Note the value of the parameter passed to the Rules Component, i.e. flagged-node:author (the author of the node being flagged). Obviously, you want to limit access to this flag to users like your admin only.

That's really it.

PS: you don't really need to use a Rules Component, since you could "integrate" (hardcode) what the Rules Component does in your actual rule also. So that's rather a matter of coding style. If you'd make your eMail subject and message body another parameter for the Rules Component, you can re-use that Rules Component for all sorts of eMails you want to send via Rules. And if some day you'd want to replace sending eMails (by Rules) by using the (amazing) Message module, you'd only have to adapt your Rules Component for it.