commit 0bf9242864d103396f6aa918e96d3fb80bbf5c7e Author: Peter Edmond Date: Sat Dec 14 22:18:13 2024 +0000 Initial email scrip work diff --git a/README.md b/README.md new file mode 100644 index 0000000..4492407 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +#About + +This repository contains a collection of RT Scrips for various tasks, so that they can be used as a collection of recipies for future development diff --git a/SendEmail.txt b/SendEmail.txt new file mode 100644 index 0000000..51e91b0 --- /dev/null +++ b/SendEmail.txt @@ -0,0 +1,73 @@ +**** Custom condition: + +return 0 unless $self->TicketObj->QueueObj->Name eq "test-queue"; + +# Check https://rt-wiki.bestpractical.com/wiki/CustomConditionSnippets - for solutions +my $txn = $self->TransactionObj; +my $type = $txn->Type; +return 0 unless $type eq "Status" + || ( $type eq 'Set' && $txn->Field eq 'Status'); +return 0 unless $txn->OldValue eq "new"; +return 0 unless $txn->NewValue eq "open"; + +return 1; + + + +**** Custom action preparation code: + +require RT::Action::SendEmail; +use strict; +use vars qw/@ISA/; +@ISA = qw(RT::Action::SendEmail); +$self->SetRecipients(); +$self->SUPER::Prepare(); +$self->SUPER::Commit(); + +sub SetRecipients { +my $self = shift; +my $ticket = $self->TicketObj; +my ( @To, @PseudoTo, @Cc, @Bcc ); +my $arg ='Owner,Requestor,AdminCc,Cc'; +##Requestor +push @To, $ticket->Requestors->MemberEmailAddresses; + +##FriendlyToLineFormat +#if ( RT->Config->Get('UseFriendlyToLine') ) { +# unless (@To) { +# push @PseudoTo, +# sprintf RT->Config->Get('FriendlyToLineFormat'), $arg, $ticket->id; +# } +#} + +my $creator = $self->TransactionObj->CreatorObj->EmailAddress(); +#Strip the sender out of the To, Cc and AdminCc and set the +# recipients fields used to build the message by the superclass. +# unless a flag is set +if (RT->Config->Get('NotifyActor')) { + @{ $self->{'To'} } = @To; + @{ $self->{'Cc'} } = @Cc; + @{ $self->{'Bcc'} } = @Bcc; +} +else { + @{ $self->{'To'} } = grep ( lc $_ ne lc $creator, @To ); + @{ $self->{'Cc'} } = grep ( lc $_ ne lc $creator, @Cc ); + @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc ); +} + +} + +1; + +**** Custom action commit code: (Useful for diagnostics) + + +my $ticket = $self->TicketObj; + +if ($self->TicketObj->Status() ne "new") { + return 1; +} + +$ticket->Comment(Content => 'Script #21 - sending email to requestor'); +$ticket->Comment(Content => 'Status is: '.$self->TicketObj->Status()); +return 1;