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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With