Resolve the participant group (team) to its members and send one e-mail with all addresses (or one per member), using the members' e-mail attribute:
// service flow script: e-mail addresses of every member of a team / participant group
var team = tw.system.org.findRoleByName(tw.local.teamName); // participant group / team by name (nested groups expanded by allUsers)
if (team == null) throw new Error("Team not found: " + tw.local.teamName);
var users = team.allUsers, addresses = [];
for (var i = 0; i < users.length; i++) {
var mail = users[i].attributes.get("Email Address") || users[i].emailAddress; // attribute name as in Process Admin; TWUser.emailAddress on newer releases
if (mail && mail != "") addresses.push(String(mail));
}
tw.local.to = addresses.join(";"); // Send E-Mail accepts several recipients separated by ; (or , on some releases)
// then the System Data "Send E-Mail" service: to = tw.local.to, subject, body (HTML), from = tw.env.mailFromVariants: one personalised mail per member (loop over users and call Send E-Mail each time - slower but allows "Dear Ana"), BCC for large groups (the Send E-Mail service has bcc on BAW), and a distribution list address in the team's description as a fallback when the group is huge. For the team of a task (the potential owners of a specific task), read the task's team (tw.system.findTaskByID(id).assignedTo returns the user or the team) and resolve it the same way. Keep the team lookup cached when the mail is sent from a loop (LDAP cost).
References