I have a content type in which i have a list where all the Roles are displayed.I want the user to select the roles from the list to which user wants to send emails.
Example : i have a list of HR, Marketing, Finance Department. So when the user Select HR and Marketing from the list it should send email to only HR and Marketing. Can any one help that how we can archive this using Rules. Help will be greatly appreciated. thanks in advance.

CommentFileSizeAuthor
Capture.PNG2.93 KBramanmadi
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

Component: Forms Support » Rules Core
Issue tags: -#rules
giorgio79’s picture

Meh, create a View with the users you want and you can send email via a VBO...

TR’s picture

Status: Active » Fixed

Seems pretty easy with Rules ... Here's how you set it up:

On your content type (I will use "Article" for convenience), add a "List (text)" field. I will call it "Department emails". Pick the "Select" widget (or "Check boxes/radio buttons" if you prefer). Set the allowed values to be your department e-mail addresses like this:

hr@example.com|HR Department
marketing@example.com|Marketing Department
finance@example.com|Finance Department

That way the actual e-mail addresses will be hidden and the department names will be shown on the content. Limit the number of selections if you want.

Now go to the manage display tab for the article content type, open the "Custom display settings" fieldset at the bottom, and check "Tokens" (and only "Tokens"). Save. Then go to the "Tokens" subtab under manage display and choose "Key" for the format of your "Department emails" field. Save.

And here's the Rule which will send email to the selected departments, whenever a new Article is created or and existing Article is updated. Choose whatever event(s) you like to trigger this as long as it provides an article node in the context.

{ "rules_send_email_to_selected_departments_on_article_save" : {
    "LABEL" : "Send email to selected departments on article save",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_i18n" ],
    "ON" : {
      "node_update--article" : { "bundle" : "article" },
      "node_insert--article" : { "bundle" : "article" }
    },
    "DO" : [
      { "mail" : {
          "to" : "[node:field_department_emails]",
          "subject" : "test",
          "message" : "test",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

TR’s picture