
Hi all, is there an OTRS feature which would be able to bouce every new mail, which ends in specific queue? I have script which was doing that in previous version of OTRS, but it seems, that it's not compatible with OTRS version 2.x. Can someone help debug it - see attached file. TIA, --alexm #!/usr/bin/perl -w use lib ("/opt/otrs/" , "/opt/otrs/Kernel/cpan-lib/"); use Kernel::Config; use Kernel::System::Log; use Kernel::System::DB; use Kernel::System::Ticket; use Kernel::System::User; use Data::Dumper; my $ConfigObject = Kernel::Config->new(); my $LogObject = Kernel::System::Log->new( ConfigObject => $ConfigObject, ); my $DBObject = Kernel::System::DB->new( ConfigObject => $ConfigObject, LogObject => $LogObject, ); my $TimeObject = Kernel::System::Time->new( ConfigObject => $ConfigObject, ); my $TicketObject = Kernel::System::Ticket->new( ConfigObject => $ConfigObject, LogObject => $LogObject, DBObject => $DBObject, TimeObject => $TimeObject, ); my $UserObject = Kernel::System::User->new( ConfigObject => $ConfigObject, LogObject => $LogObject, DBObject => $DBObject, ); my $user_id = $UserObject->GetUserIdByName(User=>'root@localhost'); my $ticket_num; #=$ARGV[0]; my $ticket_id; #=$ARGV[1] || 0; my @AllTicketIDs; sub bounce { my ($ticket_id,$article)=@_; #my $ticket_id=shift @_; $ticket_num=0; if (!$ticket_num) { # We only got a ticket ID $ticket_num=$TicketObject->TicketNumberLookup(TicketID=>$ticket_id); } # check how many articles ticket has my @ArticleIDs = $TicketObject->ArticleIndex( TicketID => $ticket_id ); if (@ArticleIDs <= 1) { # Let's see if it's a new mail or followup $subject='[BLA #: '.$ticket_num.'] '.$article{Subject}; } else { $subject=$article{Subject}; } # check if article has attachments my %AttachIndex = $TicketObject->ArticleAttachmentIndex( ArticleID => $article{ArticleID}, FileID => 1 ); my @test = sort keys %AttachIndex; # collect parameters for bouncing mail %ArticleSendParams=(TicketID=>$ticket_id, From=>$article{From}, To=>$article{To}, Subject =>$subject, Cc =>$article{Cc}, Bcc =>'valid@email.com', Body =>$article{Body}, UserID=>$user_id, Loop =>1, ArticleType =>'email-external', SenderType =>'system', HistoryComment =>'AutoForward to valid@email.com', HistoryType =>'Forward'); #print $ArticleSendParams; if (@test) { # if article has attachments, add them to the parameters for bouncing mail foreach $key (@test) { my %Attach = $TicketObject->ArticleAttachment( ArticleID => $article{ArticleID}, FileID => $key); $rA = \%Attach; %ATS=('Content' => $$rA{"Content"},'ContentType' => $$rA{"ContentType"}, 'Filename' => $$rA{"Filename"}); push(@ATS,{%ATS}); $ArticleSendParams{'Attach'}=[@ATS]; } } #print $ArticleSendParams; #print Dumper(\%ArticleSendParams); #print Dumper(\@ATS); #print Dumper(\@Attachments); # send bouncing mail $TicketObject->ArticleSend(%ArticleSendParams); # change ticket status from new to open $TicketObject->StateSet(TicketID=>$ticket_id, UserID=>$user_id, State=>'open'); =item $TicketObject->ArticleSend( TicketID=>$ticket_id, From=>$article{From}, To=>'valid@email.com', Subject =>$subject, Body => $article{Body}, UserID=>$user_id, Loop => 1, ArticleType => 'email-external', SenderType => 'system', HistoryComment => 'AutoForward to valid@email.com', HistoryType => 'Forward'); $TicketObject->StateSet(TicketID=>$ticket_id, UserID=>$user_id, State=>'open'); $TicketObject->MoveTicket(TicketID=>$ticket_id, Queue=>'important_queue', UserID=>1); =cut } # find new tickets or new followups in queue important_queue @AllTicketIDs = $TicketObject->TicketSearch( Result => 'ARRAY', Limit => 10000, Queues => ['important_queue'], States => ['new'], UserID=>1); foreach $ticket_id (@AllTicketIDs) { %article=$TicketObject->ArticleLastCustomerArticle(TicketID=>$ticket_id); #print($article{ArticleID}); bounce($ticket_id,$article{ArticleID}); }

Hi Alex, no, there is no existing script. A question, in what case do you use this? Thanks, -Martin Alex Mihicinac wrote:
Hi all,
is there an OTRS feature which would be able to bouce every new mail, which ends in specific queue? I have script which was doing that in previous version of OTRS, but it seems, that it's not compatible with OTRS version 2.x. Can someone help debug it - see attached file.
TIA,
--alexm
------------------------------------------------------------------------
#!/usr/bin/perl -w use lib ("/opt/otrs/" , "/opt/otrs/Kernel/cpan-lib/"); use Kernel::Config; use Kernel::System::Log; use Kernel::System::DB; use Kernel::System::Ticket; use Kernel::System::User; use Data::Dumper;
my $ConfigObject = Kernel::Config->new(); my $LogObject = Kernel::System::Log->new( ConfigObject => $ConfigObject, ); my $DBObject = Kernel::System::DB->new( ConfigObject => $ConfigObject, LogObject => $LogObject, ); my $TimeObject = Kernel::System::Time->new( ConfigObject => $ConfigObject, );
my $TicketObject = Kernel::System::Ticket->new( ConfigObject => $ConfigObject, LogObject => $LogObject, DBObject => $DBObject, TimeObject => $TimeObject, ); my $UserObject = Kernel::System::User->new( ConfigObject => $ConfigObject, LogObject => $LogObject, DBObject => $DBObject, ); my $user_id = $UserObject->GetUserIdByName(User=>'root@localhost');
my $ticket_num; #=$ARGV[0]; my $ticket_id; #=$ARGV[1] || 0; my @AllTicketIDs;
sub bounce { my ($ticket_id,$article)=@_; #my $ticket_id=shift @_; $ticket_num=0;
if (!$ticket_num) { # We only got a ticket ID $ticket_num=$TicketObject->TicketNumberLookup(TicketID=>$ticket_id); }
# check how many articles ticket has my @ArticleIDs = $TicketObject->ArticleIndex( TicketID => $ticket_id );
if (@ArticleIDs <= 1) { # Let's see if it's a new mail or followup $subject='[BLA #: '.$ticket_num.'] '.$article{Subject}; } else { $subject=$article{Subject}; }
# check if article has attachments my %AttachIndex = $TicketObject->ArticleAttachmentIndex( ArticleID => $article{ArticleID}, FileID => 1 );
my @test = sort keys %AttachIndex;
# collect parameters for bouncing mail %ArticleSendParams=(TicketID=>$ticket_id, From=>$article{From}, To=>$article{To}, Subject =>$subject, Cc =>$article{Cc}, Bcc =>'valid@email.com', Body =>$article{Body}, UserID=>$user_id, Loop =>1, ArticleType =>'email-external', SenderType =>'system', HistoryComment =>'AutoForward to valid@email.com', HistoryType =>'Forward');
#print $ArticleSendParams; if (@test) { # if article has attachments, add them to the parameters for bouncing mail
foreach $key (@test) { my %Attach = $TicketObject->ArticleAttachment( ArticleID => $article{ArticleID}, FileID => $key); $rA = \%Attach; %ATS=('Content' => $$rA{"Content"},'ContentType' => $$rA{"ContentType"}, 'Filename' => $$rA{"Filename"}); push(@ATS,{%ATS}); $ArticleSendParams{'Attach'}=[@ATS]; } }
#print $ArticleSendParams; #print Dumper(\%ArticleSendParams); #print Dumper(\@ATS); #print Dumper(\@Attachments);
# send bouncing mail $TicketObject->ArticleSend(%ArticleSendParams);
# change ticket status from new to open $TicketObject->StateSet(TicketID=>$ticket_id, UserID=>$user_id, State=>'open');
=item $TicketObject->ArticleSend( TicketID=>$ticket_id, From=>$article{From}, To=>'valid@email.com', Subject =>$subject, Body => $article{Body}, UserID=>$user_id, Loop => 1, ArticleType => 'email-external', SenderType => 'system', HistoryComment => 'AutoForward to valid@email.com', HistoryType => 'Forward');
$TicketObject->StateSet(TicketID=>$ticket_id, UserID=>$user_id, State=>'open');
$TicketObject->MoveTicket(TicketID=>$ticket_id, Queue=>'important_queue', UserID=>1);
=cut }
# find new tickets or new followups in queue important_queue @AllTicketIDs = $TicketObject->TicketSearch( Result => 'ARRAY', Limit => 10000, Queues => ['important_queue'], States => ['new'], UserID=>1); foreach $ticket_id (@AllTicketIDs) { %article=$TicketObject->ArticleLastCustomerArticle(TicketID=>$ticket_id); #print($article{ArticleID}); bounce($ticket_id,$article{ArticleID}); }
------------------------------------------------------------------------

Hi Martin, Martin Edenhofer wrote:
Hi Alex,
no, there is no existing script.
A question, in what case do you use this?
Well, we need this kind of feature for bouncing mail to specific
mail-list (before bounce, mail must get ticket number).
btw, my script was not working because there were new attributes added
to ArticleSend (which are required and that was not mentioned in
descripton ;-).
Are those required: Charset => 'ISO-8859-2', Type => 'text/plain' ?
=item ArticleSend()
send article via email and create article with attachments
my $ArticleID = $TicketObject->ArticleSend(
TicketID => 123,
ArticleType => 'note-internal' #
email-external|email-internal|phone|fax|...
SenderType => 'agent', # agent|system|customer
From => 'Some Agent
participants (2)
-
Alex Mihicinac
-
Martin Edenhofer