Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emailing All Users In A Specific Role From Sitecore Workflow

How can I send workflow notifications to all users in a Sitecore role? For instance, the next step in the workflow is for the Legal department to approve or reject. How can I make Sitecore send emails to all users in the Legal Approver role? I'm trying to avoid maintaining a distribution list and would like to grab users' email addresses dynamically.

like image 939
kirk.burleson Avatar asked Dec 29 '10 14:12

kirk.burleson


2 Answers

Sitecore security is based on ASP.NET security model. Hence, you can use standard ASP.NET API to obtain users of a certain role:

var users = System.Web.Security.Roles.GetUsersInRole("yourdomain\yourrole");

And later on iterate through the found users and read Email property:

foreach (var user in users)
{
  var membershipUser = System.Web.Security.Membership.GetUser(user);
  var email = membershipUser.Email;
  // use this email to send the message to that user
}

I might be mistaken in syntax details, but I'm sure you can figure it out knowing the general idea.

like image 98
Yan Sklyarenko Avatar answered Nov 09 '22 12:11

Yan Sklyarenko


To resolve indirect membership you can use the Sitecore.Security.Accounts.RolesInRolesManager which also returns user accounts which are indirect part of the role specified.

RolesInRolesManager.GetUsersInRole(Role.FromName(roleName), true)
like image 4
David Stöger Avatar answered Nov 09 '22 14:11

David Stöger