RT3 Hack: Send mail to group address. I love it!

OK. Nobody has responded to my earlier e-mail on avoiding
the use of RT::GroupMember, so I’m posting my code. I
look forward to your comments! :slight_smile:

Situation: You have a group that is AdminCc on a queue
or ticket. Everyone in the group gets copied on comments
and replies but since they are just taking turns being
on call, not everyone wants a copy of every stupid
message. Why can’t RT just send notifications to a
group e-mail address? Now it can!

I modified MemberEmailAddresses in my Group_Local.pm
with the code below. Note that I was too lazy to
add a group e-mail address to the RT3 database so
I just put it in the group description. As long
as it is separated from the rest of the description
by whitespace everything should be OK.

Please send feeback so I can make fixes before posting
the code to the Wiki.

-Todd

{{{ MemberEmailAddresses

=head2 MemberEmailAddresses

Returns an array of the email addresses of all of this group’s members
unless the group has an e-mail address embedded in it’s description
in which case that address is used instead.

=cut

sub MemberEmailAddresses {
my $self = shift;

my %addresses;

if ($self->Domain ne ‘RT::Queue-Role’ && $self->Domain ne ‘RT::Ticket-Role’) {
my $members = $self->UserMembersObj();
while (my $member = $members->Next) {
$addresses{$member->EmailAddress} = 1;
}
}
else {
##### Go through each group within this group and
##### if it is UserDefined and you can get an
##### e-mail address from the description, put
##### that address in the hash instead.
my $members = $self->MembersObj;
while (my $member = $members->Next) {
my $principal = $member->MemberObj;
if ($principal->IsGroup) {
my $group_object = $principal->Object;
if ($group_object->Domain eq ‘UserDefined’ && $group_object->Description =~ /(\S+@\S+)/) {
$addresses{$1} = 1;
}
else {
my @addrs = $group_object->MemberEmailAddresses;
map {$addresses{$_} = 1} @addrs;
}
}
else {
my $member_object = $principal->Object;
$addresses{$member_object->EmailAddress} = 1;
}
}

}

return(sort keys %addresses);

}

}}}