How do not autoreply to certain addresses with certain subject in their mails

Dear RT users /admins:
We are struggling to get RT to not autoreply to certain addresses with certain subject in their mails.
Is there any way to set any autoreply related variable to avoid sending an autoreply based on this condition?
We think we should use something like:

if( $self->TicketObj->RequestorAddresses =~ /mail@address.com/) && $self->TicketObj->Subject =~/mail subjetct/{
$self->TicketObj->Do Not Autoply;
}
return 1;

Also, we are unsure exactly on how we should fill all boxes in the global scrip interface.

We have searched the documentation several times with no luck until now.
Any help will be appreciated. Thank you very much in advance.
Regards,
José.

For the condition, just return 0; instead of that $self->TicketObj->Do No Autoply;. That way the condition isn’t true so the associated action commit (which I assume is the auto reply you’re turning off) won’t be fired.

For the “Condition” drop-down you want to select “user defined”, docs on actions and conditions can be found here:

https://docs.bestpractical.com/rt/5.0.1/customizing/scrip_conditions_and_action.html

Hello, GreenJimll:
Thank you!
I’m giving it a try right away.
By the way, this code goes into the box called Custom Action Preparation Code, right?
Are the two other boxes suppossed to be empty?
Thank you very much.

Depends on how you’re setting things up.

If you’re using a pre-existing condition (such as “On Create” or “On Comment”, etc) with a custom action, then this can go in the action preparation section, with your custom action’s actual commit code in the last text box.

If however you’re using a pre-defined action and just want to change the condition, this will need to go on in the first, custom condition box.

You might want some other conditions included as well (for example checking that the transaction type was a particular value or what the status of the ticket is), as otherwise this will fire on all transactions that don’t have that subject pattern sent by that requestor email.

Hello again, GreenJimll:
First of all, let me thank you all your help.
Unfortunately, after several trials I wasn’t able to make it work. This is how I set it up, which I am not sure if it is correct. To make it clear, let me please be explicit on how I have donde it:

Condition: User Defined.
Action: Autoreply to requestors.
Layout: blank.
Custom condition:
if( $self->TicketObj->RequestorAddresses =~ /myMailAddress@gmail.com/) {
if ($self->TicketObj->Subject =~/mySuject/){
return 0;
}
}
return 1;

Custom preparation code box and custom personalized action box are empty.

Could you please point me what you guess?

Thank you very much!

Best regards,
José.

Is your email template blank?

Hello,

I tried setting it to blank and also Autoreply in HTML, but both replied with the autocreation message, which is what I am trying to avoid.

Thank you.

Regards,
José.

Also you may need to escape the @ symbol in your regex:

 if( $self->TicketObj->RequestorAddresses =~ /myMailAddress\@gmail.com/) {

Since Perl may interpret that as a variable

1 Like

Hello, GreenJimll:

I am still getting autoreply messages. Could you please tell how you would set the drop down menus? I tried several combinations with no luck.

I see output while reading the logs, so I guess the code is right, but somehow I am not setting the correct options.

Thank you in advance!

Best regards,
José

If you had a blank template and still got an autoreply message, you might want to check if you have any other scrips that will fire off with that message. Remember that all the applied scrips that are valid when a transaction takes place will be queued up to execute one after the other.

Hello:
Ok, I got it. Scrip 8 is still being launched. Nonetheless, my script, set up with the condition on create and user defined action, is skipped because it didn’t prepare (this is what I see in the log). Why is this happening?
Thank you and sorry to keep disturbing you with this.
Regards,
José.

If it’s complaining about preparing, it tends to imply its trying to fire off a custom action still (as prepare and commit are the two parts of an action), rather than just a custom condition.

Hello.
Sorry to bother again.
Now I see output coming from the script which I get by using RT::Logger. Nonetheless, at the same time I’m seeing in the logs “Skipping Scrip #26 because it isn’t applicable”. The script no. 26 is the scrip I am working on.
Could you please tell me why this might be happening?
Thank you very much in advance.
Regards,
José.

That means your condition isn’t returning a true value. I’d add some logging to the custom condition and see if something isn’t returning true where you expect it to be

Dear admins/staff:

The scrip commits if I return 1 instead of returning 0 as GreenJim proposed, but is still sending mail, so I guess I am doing something wrong. This is the code I have now:

if ($self->TransactionObj->Type eq ‘Create’) {
if( $self->TicketObj->RequestorAddresses =~ /address@gmail.com/){
$RT::Logger->debug(“sender identified”);
if( $self->TicketObj->Subject =~/mySubject/){
$RT::Logger->debug(“should not send mail”);
return 1;
}else{return};
}else{return};
}else{return};
return;

I can see debug output in the logs saying “should not send mail”, but it is still autoreplying anyway.
To let it clear, the condition is user defined, my action is autoreply to requestors and the template is autoreply in HTML.

If true, I would have to return 1 or return 0? As you see, I’m a bit lost.

Best regards,
José.

When you return 0 ( false ) the scrip action will not run. So when the condition where the auto reply shouldn’t run is met you want to return 0.

Then when it should run you can just return 1

1 Like

Thanks a lot. I have it working now. Marking thread as solved.