Email all users in a specific role from Sitecore Workflow

How can I send workflow notifications to all users in the Sitecore role? For example, the next step in the workflow is for the Legal Department to approve or reject. How can I get Sitecore to send emails to all users in the Legal Approver role? I am trying to avoid saving the mailing list and would like to receive dynamic email addresses of users.

+5
source share
2 answers

Sitecore security is based on the ASP.NET security model. Therefore, you can use the standard ASP.NET API to get users of a specific role:

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

And later, repeat the search for found users and read the 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 may be mistaken in the details of the syntax, but I am sure that you can understand this by knowing the general idea.

+8
source

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

RolesInRolesManager.GetUsersInRole(Role.FromName(roleName), true)
+3
source

All Articles