====== Auto-Queue scrips ======
===== Auto Queue based on sender e-mail =====
This scrip (not a typo, a scrip is an RT Script) can be added in the global scrip section and will automatically put a ticket in the proper queue based on the sender's e-mail address. In this case, we have senders coming from different domains (@example.net and @example2.com), and we want to put them into the queue's **Example** and **Example 2 Queue** when a new ticket arrives. Note: the queues must exist before this.
The hash %domain_map contains a [[https://en.wikipedia.org/wiki/Regular_expression|Regular Expression]] (aka regex) to match. If the regex matches, the new ticket will be placed in the proper queue.
Note: A handy regex tester I use quite a bit is located at [[https://regex101.com/]]
* Description: Place all new tickets in correct queue, where possible
* Condition: On Create
* Action: User Defined
* Template: Blank
* Enabled: check
* Custom Condition: empty
* Custom action preparation code: return 1;
* Custom action commit code: code which follows
# Written by RWR, taken from
# https://forum.bestpractical.com/t/changing-queue-based-on-incoming-email-address/20925
# hash of all the possible domains, and matching queues
my %domain_map = (
'@.?example.net' => 'Example',
'@.?example2.com' => 'Example 2 Queue'
);
#Check each of our defined domains for a match
foreach my $domainKey (keys %domain_map ) {
if ( $self->TicketObj->RequestorAddresses =~ /^.*?${domainKey}/ ) {
# Domain matches - move to the right queue
$self->TicketObj->SetQueue($domain_map{$domainKey});
}
}
return 1;
===== Placing mail to different addresses in different queues =====
This is easy to do in RT, if you are using aliases to route them. For example, if you have //support@example.com// set up as a forwarder to your RT server, you would create an entry like this in your aliases file on the RT server.
support: "|/opt/rt5/bin/rt-mailgate --queue general --action correspond --url https://rt.example.com/rt/"
support-comment: "|/opt/rt5/bin/rt-mailgate --queue general --action comment --url https://rt.example.com/rt/"
which will redirect the incoming mail to Request Tracker's interface on the machine.
In order to add new clients, you can create different aliases for each to correspond with; in this case, client1 and client2, which would go into the queue's Client1 and Client 2 respectively.
support: "|/opt/rt5/bin/rt-mailgate --queue general --action correspond --url https://rt.example.com/rt/"
support-comment: "|/opt/rt5/bin/rt-mailgate --queue general --action comment --url https://rt.example.com/rt/"
client1: "|/opt/rt5/bin/rt-mailgate --queue client1 --action correspond --url https://rt.example.com/rt/"
client1-comment: "|/opt/rt5/bin/rt-mailgate --queue client1 --action comment --url https://rt.example.com/rt/"
client2: "|/opt/rt5/bin/rt-mailgate --queue 'Client 2' --action correspond --url https://rt.example.com/rt/"
client2-comment: "|/opt/rt5/bin/rt-mailgate --queue 'Client 2' --action comment --url https://rt.example.com/rt/"
Now, mail sent to client1@example.com would be forwarded to client1@rt.example.com, which would be picked up by line 3 above and sent to RT, placing the ticket into the queue Client1. e-mail to client2@example.com would be sent to client2@rt.example.com which would go into RT, and place the new ticket in the queue Client 2.