Send emails to a related field group

I’d like to suggest adding the functionality to be able to send emails to a related field for Security Groups. I have already made a custom modification that migh worth moving to 7.1.2.

In aow_utils.php: line 610, add the related SecurityGroups to the dropdown:

 if($obj instanceof Person || $obj instanceof Company||$obj instanceof SecurityGroup){

In actionSendEmail.php: around line 188, replace the case 'Related Field" section with:

                    case 'Related Field':
                        $emailTarget = $params['email'][$key];
                        $relatedFields = $bean->get_related_fields();
                        $field = $relatedFields[$emailTarget];
                        if($field['type'] == 'relate'){
                            $linkedBeans = array();
                            $id = $bean->$field['id_name'];
                            $linkedBeans[] = BeanFactory::getBean($field['module'],$id);
                            $linkedBeans = $bean->get_linked_beans($field['link'],$field['module']);
                          $linkedBean = $linkedBeans[0];
                          if ($linkedBean->object_name !='SecurityGroup'){  
                            $emails[$params['email_to_type'][$key]][] = $linkedBean->emailAddress->getPrimaryAddress($linkedBean);
                          }else {
                            $users = array();
                            $users = $linkedBean->get_linked_beans( 'users','User');
                            $r_users = array();
                            foreach($users as $user){
                                $emails[$params['email_to_type'][$key]][] = $user->emailAddress->getPrimaryAddress($user);

Can’t you do this using Workflows? I send emails all over the place by creating workflow automation.

The idea is that we have a before_save hook that fills in different fields which are relationships to groups. At each step of the workflow, different groups of people need to be notified. These groups are defined at the opportunity level (in our case) and calculated by the hook based on lookups. So it is the workflow that makes the decisión on which groups to send the notification, but the actual groups depend on the opportunity. This reduces significantly the number of workflows, while still retaining the business logic at the workflow level and limiting the hook logic to calculations and lookups.