Restrict auto-replies to a local domain

Is there an option to restrict RT from sending email to external domain addresses? My RT is primarily an internal tool to the business, but with the email setup occasionally an external email address gets in as a requestor. Can I disable any auto-responses to that external email address, but still allow deliberate correspondence to those addresses?

I’ve looked thru RT_Config.pm and not found options that relate to this. My next thought is to customize the scrip’s that On Create Auto Reply. Is there another way I’ve missed?

I think there are two ways:

  1. Customize On Create Auto Reply
    Create custom condition that checks Requestors and return false if the requestor is not local

  2. Modify Autoreply action
    copy lib/RT/Action/Autoreply.pm to local/lib/RT/Action/Autoreply.pm
    replace

push(@{$self->{‘To’}}, $self->TicketObj->Requestors->MemberEmailAddresses);

with

push(@{$self->{‘To’}}, (grep /local.domain/i, $self->TicketObj->Requestors->MemberEmailAddresses));

where local.domain is your local domain =)

clear cache and restart web-server

1 Like

That’s the options I found. I thought modifying the scrip might be more maintainable. I found https://rt-wiki.bestpractical.com/wiki/NoReplyAddress and modified it to my purpose.

#   INTERRUPT NORMAL CORRESPONDENCE, DON'T SEND MAIL IF
#   the from: ADDRESS ON THE EMAIL MATCHES  the pattern
my $Ticket = $self->TicketObj;
my $Id = $self->TicketObj->id;
my $Trans = $self->TransactionObj;
my $FirstAttch = $self->TransactionObj->Attachments->First();


#   BAIL OUT UNLESS THIS IS OF TYPE: Create
#   (e.g. IF IT IS OF TYPE: Create, Comment, etc)
return 0 unless $Trans->Type eq "Create"; 

#   GET THE MESSAGE ATTACHMENT: 
my $msgatt = $Trans->Message->First; 

#   PROCEED NORMALLY (GO AHEAD AND NOTIFY REQUESTORS) UNLESS THERE IS 
#   A MESSAGE ATTACHMENT (AND THEREFORE IS COMING FROM EMAIL)
return 1 unless $msgatt; 
 
#   VARIABLE-IZE WHO THE EMAIL WAS SENT TO:
my $from = $FirstAttch->GetHeader('From'); 

#   FOR FULL DEBUGGING (COURTESY BEST PRACTICAL), UNCOMMENT THESE NEXT 4 LINES:
# use Data::Dumper;
# warn "Headers are: " . $self->TransactionObj->Attachments->First->Headers;
# my $address_ref = $self->TransactionObj->Attachments->First->Addresses();
# warn "Addresses are: " . Dumper($address_ref); warn "Bcc is: " . $address_ref->{'Bcc'}[0]->as_string;


#   ANOTHER CHANGE TO GET OUT, THIS TIME IF THE "From:" ADDRESS IS EMPTY:
return 1 unless ($from);

#   CREATE AN ARRAY OF EMAIL *OBJECTS*
my @addr = Mail::Address->parse($from);

$RT::Logger->debug("Scrip #5: DEBUG: From contains " . scalar(@addr) . " addresses.");


my ($address);
foreach my $addrobj (@addr) {
     $address = lc $RT::Nobody->UserObj->CanonicalizeEmailAddress($addrobj->address);
     $RT::Logger->debug("Scrip #5: Ticket #$Id correspondence (Canonicalized) address = $address");
     if ($address !~ m/mydomain.net/) {
         $RT::Logger->info("On Create email for ticket #$Id -- ($address) - suppressing notice for this transaction.");
         return 0;
     }
}


return 1;

This suppresses auto-replies to email tickets coming from outside my local domain, when put as a user defined condition on the Auto Reply to requestors scrip.

1 Like