Difference between revisions of "DueDateRemindersByEmail"

From Request Tracker Wiki
Jump to navigation Jump to search
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The following script will send email notifications on Tickets that are over due.
The following script will send email notifications on Tickets that are over due.
Notes by [[User:Barton|Barton]]: I ran this page through a [[lowHangingFruit#sed_script_to_clean_up_nowiki_tagged_code|sed script]] that fixed the formatting of the nowiki formatted code blocks. You are encouraged to check the history of this page and make sure that I didn't mess anything up.


== New version ( 3.1 ) ==
== New version ( 3.1 ) ==
Line 11: Line 13:
find it here: http://pastebin.com/gj5R7wm2
find it here: http://pastebin.com/gj5R7wm2


<nowiki> #!/usr/bin/perl
    ####################### RT Email Notification Script ####################
####################### RT Email Notification Script ####################
    ####
####
    #### Author: Daniely Yoav / Qball Technologies Ltd.
#### Author: Daniely Yoav / Qball Technologies Ltd.
    #### Email: yoavd@qballtech.net
#### Email: yoavd@qballtech.net
    #### Date: 05/06/05
#### Date: 05/06/05
    ####
####
    #### Modified by: Tomas Borland Valenta
#### Modified by: Tomas Borland Valenta
    #### Email: tomas at trustica dot cz
#### Email: tomas at trustica dot cz
    #### Date: 2007/03/12
#### Date: 2007/03/12
    ####
####
    #### Modified by: Tim Schaller
#### Modified by: Tim Schaller
    #### Email: tim-rt@torzo.com
#### Email: tim-rt@torzo.com
    #### Date: 2008/06/17
#### Date: 2008/06/17
    ####
####
    #### Modified by: Vaclav Vobornik
#### Modified by: Vaclav Vobornik
    #### Email: vaclav dot vobornik at commerzbank dot com
#### Email: vaclav dot vobornik at commerzbank dot com
    #### Date: 2008/07/04
#### Date: 2008/07/04
    ####
####
    #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
#### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
    ####
####
    #### Version: 3.1
#### Version: 3.1
    ####
####
    #### Changes from 3 ( Vaclav Vobornik )
#### Changes from 3 ( Vaclav Vobornik )
    #### - Added Cc and Bcc possibilities.
#### - Added Cc and Bcc possibilities.
    ####
####
    #### Changes from 2 ( Tim Schaller )
#### Changes from 2 ( Tim Schaller )
    #### - Added multiple command line options.
#### - Added multiple command line options.
    #### - Adaptive subject line.
#### - Adaptive subject line.
    #### - Sending Admin CC emails optional.
#### - Sending Admin CC emails optional.
    ####
####
    #### Changes from 1.2 ( Tomas Borland Valenta )
#### Changes from 1.2 ( Tomas Borland Valenta )
    #### - rewriten mail subsystem
#### - rewriten mail subsystem
    #### - code cleanup
#### - code cleanup
    #### - adopted for RT 3.6.x
#### - adopted for RT 3.6.x
    #### - used some global RT config variables
#### - used some global RT config variables
    ####
####
    #### ======================================================================
#### ======================================================================
    ####
####
    #### Command line options
#### Command line options
    ####          -d          : turns dubugging on
####          -d          : turns dubugging on
    ####          -A          : Send to AdminCC ( made default not to )
####          -A          : Send to AdminCC ( made default not to )
    ####          -a <n>     : Send reminders to tickets due in <n> or less days.
####          -a &lt;n&gt;     : Send reminders to tickets due in &lt;n&gt; or less days.
    ####                      : Includes overdue tickets.
####                      : Includes overdue tickets.
    ####          -q <queue> : Only send reminder for tickets in <queue>
####          -q &lt;queue&gt; : Only send reminder for tickets in &lt;queue&gt;
    ####          -o <owner> : Only send reminders for tickets owned by <owner>
####          -o &lt;owner&gt; : Only send reminders for tickets owned by &lt;owner&gt;
    ####          -c <email> : Email in Cc
####          -c &lt;email&gt; : Email in Cc
    ####          -b <email> : Email in Bcc
####          -b &lt;email&gt; : Email in Bcc
    ####
####
    #### ======================================================================
#### ======================================================================
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue
####      : and send notices to everyone in the SysAdmin Queue
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue
####      : and send notices to everyone in the SysAdmin Queue
    ####      : Remind them about tickets due in less then 5 days.
####      : Remind them about tickets due in less then 5 days.
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue.
####      : and send notices to everyone in the SysAdmin Queue.
    ####      : Send copies to all AdminCC on the tickest.
####      : Send copies to all AdminCC on the tickest.
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
   
    ### External libraries ###
### External libraries ###
    use strict;
use strict;
    use Getopt::Std;
use Getopt::Std;
   
    use lib ("/opt/rt3/lib");  # Change this to your RT lib path!
use lib ("/opt/rt3/lib");  # Change this to your RT lib path!
    package RT;
package RT;
    use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
    use RT::Date;
use RT::Date;
    use RT::Queue;
use RT::Queue;
    use RT::Queues;
use RT::Queues;
    use RT::Tickets;
use RT::Tickets;
   
    ################## Init ##################
################## Init ##################
    # Clean our environment
# Clean our environment
    CleanEnv();
CleanEnv();
    # Load the RT configuration
# Load the RT configuration
    RT::LoadConfig();
RT::LoadConfig();
    RT::Init();
RT::Init();
    # Set config variables
# Set config variables
    my $debug=0;
my $debug=0;
    my $from_address = $RT::CorrespondAddress; #From: address used in reports
my $from_address = $RT::CorrespondAddress; #From: address used in reports
    my $rt_url = $RT::WebURL;
my $rt_url = $RT::WebURL;
    my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
    ################## Args ##################
################## Args ##################
    my $queue        = '';
my $queue        = '';
    my $owner        = '';
my $owner        = '';
    my $advDate      = 0;
my $advDate      = 0;
    my $secInDay      = 60*60*24;
my $secInDay      = 60*60*24;
    my $sendToAdminCC = 0;
my $sendToAdminCC = 0;
    my $cc            = '';
my $cc            = '';
    my $bcc          = '';
my $bcc          = '';
   
    my %options=();
my %options=();
    Getopt::Std::getopts("Ada:q:o:c:b:",\%options);
Getopt::Std::getopts("Ada:q:o:c:b:",\%options);
   
    $queue        = $options{q} if defined $options{q};
$queue        = $options{q} if defined $options{q};
    $owner        = $options{o} if defined $options{o};
$owner        = $options{o} if defined $options{o};
    $advDate      = ( $options{a} * $secInDay ) if defined $options{a};
$advDate      = ( $options{a} * $secInDay ) if defined $options{a};
    $debug        = $options{d} if defined $options{d};
$debug        = $options{d} if defined $options{d};
    $sendToAdminCC =  $options{A} if defined $options{A};
$sendToAdminCC =  $options{A} if defined $options{A};
    $cc            = $options{c} if defined $options{c};
$cc            = $options{c} if defined $options{c};
    $bcc          = $options{b} if defined $options{b};
$bcc          = $options{b} if defined $options{b};
   
   
    ################## Variables Init ##################
################## Variables Init ##################
    my $User = new RT::User($RT::SystemUser); # Define an RT User variable
my $User = new RT::User($RT::SystemUser); # Define an RT User variable
    my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
    my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
    my $now = new RT::Date($RT::SystemUser); # get current time
my $now = new RT::Date($RT::SystemUser); # get current time
    $now->SetToNow();
$now-&gt;SetToNow();
    my $report; # Used for output
my $report; # Used for output
    my $subject; # Used as subject line
my $subject; # Used as subject line
   
    ################## Main Program ##################
################## Main Program ##################
    # Limit the ticket search to new and open only.
# Limit the ticket search to new and open only.
    $tickets->LimitStatus(VALUE => 'new');
$tickets-&gt;LimitStatus(VALUE =&gt; 'new');
    $tickets->LimitStatus(VALUE => 'open');
$tickets-&gt;LimitStatus(VALUE =&gt; 'open');
   
    # Loop through new/open tickets
# Loop through new/open tickets
    while (my $Ticket = $tickets->Next) {
while (my $Ticket = $tickets-&gt;Next) {
        # Construct POP-Up Message
    # Construct POP-Up Message
        $User->Load($Ticket->Owner);
    $User-&gt;Load($Ticket-&gt;Owner);
   
        # Compare Dates to check whether the ticket's due date is in the past + Due date exists
    # Compare Dates to check whether the ticket's due date is in the past + Due date exists
        $date->Set(Format => "ISO",Value => $Ticket->Due);
    $date-&gt;Set(Format =&gt; "ISO",Value =&gt; $Ticket-&gt;Due);
        if ($now->Unix - $date->Unix < (1 - $advDate ) or $date->Unix == -1 or $date->Unix == 0) { next; }
    if ($now-&gt;Unix - $date-&gt;Unix &lt; (1 - $advDate ) or $date-&gt;Unix == -1 or $date-&gt;Unix == 0) { next; }
   
        # Compare owner and queue if given. Skip current ticket if invalid.
    # Compare owner and queue if given. Skip current ticket if invalid.
        if ($owner) { if ( lc($User->Name) ne lc($owner) ) { next; } }
    if ($owner) { if ( lc($User-&gt;Name) ne lc($owner) ) { next; } }
        if ($queue) { if ( lc($Ticket->QueueObj->Name) ne lc($queue) ) { next; } }
    if ($queue) { if ( lc($Ticket-&gt;QueueObj-&gt;Name) ne lc($queue) ) { next; } }
   
        # Generate a report
    # Generate a report
        $report = "";
    $report = "";
        $report .= "Ticket #: " . $Ticket->id . "\n";
    $report .= "Ticket #: " . $Ticket-&gt;id . "\n";
        $report .= "Subject:  " . $Ticket->Subject . "\n";
    $report .= "Subject:  " . $Ticket-&gt;Subject . "\n";
        $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
    $report .= "Queue:    " . $Ticket-&gt;QueueObj-&gt;Name . " (". $Ticket-&gt;QueueObj-&gt;AdminCcAddresses .") \n";
        $report .= "Owner:    " . $User->Name ."\n";
    $report .= "Owner:    " . $User-&gt;Name ."\n";
        $report .= "Due date: " . $date->ISO . "\n";
    $report .= "Due date: " . $date-&gt;ISO . "\n";
        $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
    $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket-&gt;id . "\n";
   
        # Set the subject based on the due date.
    # Set the subject based on the due date.
        if( ($now->Unix - $date->Unix < 0  ) or $date->Unix == -1 ) {
    if( ($now-&gt;Unix - $date-&gt;Unix &lt; 0  ) or $date-&gt;Unix == -1 ) {
            $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is due on " . $date->ISO;
        $subject =  "Ticket #". $Ticket-&gt;id . " with owner " . $User-&gt;Name ." is due on " . $date-&gt;ISO;
        } else {
    } else {
            $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
        $subject =  "Ticket #". $Ticket-&gt;id . " with owner " . $User-&gt;Name ." is overdue";
        }
    }
   
        # Get Queue Admin CC
    # Get Queue Admin CC
        # Do we send to Admin CC as well as to owner?
    # Do we send to Admin CC as well as to owner?
        my @emails = ();
    my @emails = ();
        if ( $sendToAdminCC ) {
    if ( $sendToAdminCC ) {
            @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
        @emails = ($User-&gt;EmailAddress, split(/,/, $Ticket-&gt;AdminCcAddresses), split(/,/ , $Ticket-&gt;QueueObj-&gt;AdminCcAddresses));
        } else {
    } else {
            @emails = ($User->EmailAddress);
        @emails = ($User-&gt;EmailAddress);
        }
    }
   
        # remove duplicates
    # remove duplicates
        my %temp = (); @emails = grep ++$temp{$_} < 2, @emails;
    my %temp = (); @emails = grep ++$temp{$_} &lt; 2, @emails;
        send_report(@emails);
    send_report(@emails);
    }
}
   
    # Close RT Handle
# Close RT Handle
    $RT::Handle->Disconnect();
$RT::Handle-&gt;Disconnect();
    exit 0;
exit 0;
   
    # This procedure will send a report by mail to the owner
# This procedure will send a report by mail to the owner
    #  parameter 1 - email addresses to send to
#  parameter 1 - email addresses to send to
    # Global variables refered to:
# Global variables refered to:
    #  $subject - Subject line
#  $subject - Subject line
    #  @report - Message content
#  @report - Message content
    #  $from_address - address to send from
#  $from_address - address to send from
    #  $cc - CarbonCoby email address
#  $cc - CarbonCoby email address
    #  $bcc - BlindCarbonCopy email address
#  $bcc - BlindCarbonCopy email address
    sub send_report {
sub send_report {
        my @tos = @_;
    my @tos = @_;
        my $addr;
    my $addr;
   
        foreach $addr (@tos) {
    foreach $addr (@tos) {
            next if (length($addr) == 0);
        next if (length($addr) == 0);
            my $msg = "";
        my $msg = "";
            $msg .= "From: $from_address\n";
        $msg .= "From: $from_address\n";
            $msg .= "To: $addr\n";
        $msg .= "To: $addr\n";
            $msg .= "Cc: $cc\n" if $cc;
        $msg .= "Cc: $cc\n" if $cc;
            $msg .= "Bcc: $bcc\n" if $bcc;
        $msg .= "Bcc: $bcc\n" if $bcc;
            $msg .= "Subject: $subject\n";
        $msg .= "Subject: $subject\n";
            $msg .= "\n";
        $msg .= "\n";
            $msg .= $report;
        $msg .= $report;
   
            if ($debug) {
        if ($debug) {
                print "====== Would call '$sendmail' with this input:\n";
            print "====== Would call '$sendmail' with this input:\n";
                print "$msg\n\n";
            print "$msg\n\n";
            } else {
        } else {
                open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
            open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
                print SENDMAIL $msg;
            print SENDMAIL $msg;
                close(SENDMAIL);
            close(SENDMAIL);
            }
        }
        }
    }
    }
}
   
   
   
</nowiki>


== Old version ( 3.0 ) ==
== Old version ( 3.0 ) ==
Line 227: Line 227:
====== Version ( 3.0 ) by Tim Schaller added at 17.6.2008 ======
====== Version ( 3.0 ) by Tim Schaller added at 17.6.2008 ======


<nowiki>#!/usr/bin/perl
    ####################### RT Email Notification Script ####################
####################### RT Email Notification Script ####################
    ####
####
    #### Author: Daniely Yoav / Qball Technologies Ltd.
#### Author: Daniely Yoav / Qball Technologies Ltd.
    #### Email: yoavd@qballtech.net
#### Email: yoavd@qballtech.net
    #### Date: 05/06/05
#### Date: 05/06/05
    ####
####
    #### Modified by: Tomas Borland Valenta
#### Modified by: Tomas Borland Valenta
    #### Email: tomas at trustica dot cz
#### Email: tomas at trustica dot cz
    #### Date: 2007/03/12
#### Date: 2007/03/12
    ####
####
    #### Modified by: Tim Schaller
#### Modified by: Tim Schaller
    #### Email: tim-rt@torzo.com
#### Email: tim-rt@torzo.com
    #### Date: 2008/06/17
#### Date: 2008/06/17
    ####
####
    #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
#### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
    ####
####
    #### Version: 3
#### Version: 3
    ####
####
    #### Changes from 2 ( Tim Schaller )
#### Changes from 2 ( Tim Schaller )
    #### - Added multiple command line options.
#### - Added multiple command line options.
    #### - Adaptive subject line.
#### - Adaptive subject line.
    #### - Sending Admin CC emails optional.
#### - Sending Admin CC emails optional.
    ####
####
    #### Changes from 1.2 ( Tomas Borland Valenta )
#### Changes from 1.2 ( Tomas Borland Valenta )
    #### - rewriten mail subsystem
#### - rewriten mail subsystem
    #### - code cleanup
#### - code cleanup
    #### - adopted for RT 3.6.x
#### - adopted for RT 3.6.x
    #### - used some global RT config variables
#### - used some global RT config variables
    ####
####
    #### ======================================================================
#### ======================================================================
    ####
####
    #### Command line options
#### Command line options
    ####          -d          : turns dubugging on
####          -d          : turns dubugging on
    ####          -A          : Send to AdminCC ( made default not to )
####          -A          : Send to AdminCC ( made default not to )
    ####          -a <n>     : Send reminders to tickets due in <n> or less days.
####          -a &lt;n&gt;     : Send reminders to tickets due in &lt;n&gt; or less days.
    ####                      : Includes overdue tickets.
####                      : Includes overdue tickets.
    ####          -q <queue> : Only send reminder for tickets in <queue>
####          -q &lt;queue&gt; : Only send reminder for tickets in &lt;queue&gt;
    ####          -o <owner> : Only send reminders for tickets owned by <owner>
####          -o &lt;owner&gt; : Only send reminders for tickets owned by &lt;owner&gt;
    ####
####
    #### ======================================================================
#### ======================================================================
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue
####      : and send notices to everyone in the SysAdmin Queue
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue
####      : and send notices to everyone in the SysAdmin Queue
    ####      : Remind them about tickets due in less then 5 days.
####      : Remind them about tickets due in less then 5 days.
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####      : and send notices to everyone in the SysAdmin Queue.
####      : and send notices to everyone in the SysAdmin Queue.
    ####      : Send copies to all AdminCC on the tickest.
####      : Send copies to all AdminCC on the tickest.
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
   
    ### External libraries ###
### External libraries ###
    use strict;
use strict;
    use Getopt::Std;
use Getopt::Std;
   
    use lib ("/usr/local/rt/lib");  # Change this to your RT lib path!
use lib ("/usr/local/rt/lib");  # Change this to your RT lib path!
    package RT;
package RT;
    use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
    use RT::Date;
use RT::Date;
    use RT::Queue;
use RT::Queue;
    use RT::Queues;
use RT::Queues;
    use RT::Tickets;
use RT::Tickets;
   
    ################## Init ##################
################## Init ##################
    # Clean our environment
# Clean our environment
    CleanEnv();
CleanEnv();
    # Load the RT configuration
# Load the RT configuration
    RT::LoadConfig();
RT::LoadConfig();
    RT::Init();
RT::Init();
    # Set config variables
# Set config variables
    my $debug=0;
my $debug=0;
    my $from_address = $RT::CorrespondAddress; #From: address used in reports
my $from_address = $RT::CorrespondAddress; #From: address used in reports
    my $rt_url = $RT::WebURL;
my $rt_url = $RT::WebURL;
    my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
    ################## Args ##################
################## Args ##################
    my $queue        = '';
my $queue        = '';
    my $owner        = '';
my $owner        = '';
    my $advDate      = 0;
my $advDate      = 0;
    my $secInDay      = 60*60*24;
my $secInDay      = 60*60*24;
    my $sendToAdminCC = 0;
my $sendToAdminCC = 0;
   
    my %options=();
my %options=();
    Getopt::Std::getopts("Ada:q:o:",\%options);
Getopt::Std::getopts("Ada:q:o:",\%options);
   
    $queue        = $options{q} if defined $options{q};
$queue        = $options{q} if defined $options{q};
    $owner        = $options{o} if defined $options{o};
$owner        = $options{o} if defined $options{o};
    $advDate      = ( $options{a} * $secInDay ) if defined $options{a};
$advDate      = ( $options{a} * $secInDay ) if defined $options{a};
    $debug        = $options{d} if defined $options{d};
$debug        = $options{d} if defined $options{d};
    $sendToAdminCC =  $options{A} if defined $options{A};
$sendToAdminCC =  $options{A} if defined $options{A};
   
    ################## Variables Init ##################
################## Variables Init ##################
    my $User = new RT::User($RT::SystemUser); # Define an RT User variable
my $User = new RT::User($RT::SystemUser); # Define an RT User variable
    my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
    my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
    my $now = new RT::Date($RT::SystemUser); # get current time
my $now = new RT::Date($RT::SystemUser); # get current time
    $now->SetToNow();
$now-&gt;SetToNow();
    my $report; # Used for output
my $report; # Used for output
    my $subject; # Used as subject line
my $subject; # Used as subject line
   
    ################## Main Program ##################
################## Main Program ##################
    # Limit the ticket search to new and open only.
# Limit the ticket search to new and open only.
    $tickets->LimitStatus(VALUE => 'new');
$tickets-&gt;LimitStatus(VALUE =&gt; 'new');
    $tickets->LimitStatus(VALUE => 'open');
$tickets-&gt;LimitStatus(VALUE =&gt; 'open');
   
    # Loop through new/open tickets
# Loop through new/open tickets
    while (my $Ticket = $tickets->Next) {
while (my $Ticket = $tickets-&gt;Next) {
        # Construct POP-Up Message
    # Construct POP-Up Message
        $User->Load($Ticket->Owner);
    $User-&gt;Load($Ticket-&gt;Owner);
   
        # Compare Dates to check whether the ticket's due date is in the past + Due date exists
    # Compare Dates to check whether the ticket's due date is in the past + Due date exists
        $date->Set(Format => "ISO",Value => $Ticket->Due);
    $date-&gt;Set(Format =&gt; "ISO",Value =&gt; $Ticket-&gt;Due);
        if ($now->Unix - $date->Unix < (1 - $advDate ) or $date->Unix == -1) { next; }
    if ($now-&gt;Unix - $date-&gt;Unix &lt; (1 - $advDate ) or $date-&gt;Unix == -1) { next; }
   
        # Compare owner and queue if given. Skip current ticket if invalid.
    # Compare owner and queue if given. Skip current ticket if invalid.
        if ($owner) { if ( lc($User->Name) ne lc($owner) ) { next; } }
    if ($owner) { if ( lc($User-&gt;Name) ne lc($owner) ) { next; } }
        if ($queue) { if ( lc($Ticket->QueueObj->Name) ne lc($queue) ) { next; } }
    if ($queue) { if ( lc($Ticket-&gt;QueueObj-&gt;Name) ne lc($queue) ) { next; } }
   
        # Generate a report
    # Generate a report
        $report = "";
    $report = "";
        $report .= "Ticket #: " . $Ticket->id . "\n";
    $report .= "Ticket #: " . $Ticket-&gt;id . "\n";
        $report .= "Subject:  " . $Ticket->Subject . "\n";
    $report .= "Subject:  " . $Ticket-&gt;Subject . "\n";
        $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
    $report .= "Queue:    " . $Ticket-&gt;QueueObj-&gt;Name . " (". $Ticket-&gt;QueueObj-&gt;AdminCcAddresses .") \n";
        $report .= "Owner:    " . $User->Name ."\n";
    $report .= "Owner:    " . $User-&gt;Name ."\n";
        $report .= "Due date: " . $date->ISO . "\n";
    $report .= "Due date: " . $date-&gt;ISO . "\n";
        $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
    $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket-&gt;id . "\n";
   
        # Set the subject based on the due date.
    # Set the subject based on the due date.
        if( ($now->Unix - $date->Unix < 0  ) or $date->Unix == -1 ) {
    if( ($now-&gt;Unix - $date-&gt;Unix &lt; 0  ) or $date-&gt;Unix == -1 ) {
            $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is due on " . $date->ISO;
        $subject =  "Ticket #". $Ticket-&gt;id . " with owner " . $User-&gt;Name ." is due on " . $date-&gt;ISO;
        } else {
    } else {
            $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
        $subject =  "Ticket #". $Ticket-&gt;id . " with owner " . $User-&gt;Name ." is overdue";
        }
    }
</nowiki>


<nowiki>    # Get Queue Admin CC
        # Do we send to Admin CC as well as to owner?
    # Do we send to Admin CC as well as to owner?
        my @emails = ();
    my @emails = ();
        if ( $sendToAdminCC ) {
    if ( $sendToAdminCC ) {
            @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
        @emails = ($User-&gt;EmailAddress, split(/,/, $Ticket-&gt;AdminCcAddresses), split(/,/ , $Ticket-&gt;QueueObj-&gt;AdminCcAddresses));
        } else {
    } else {
            @emails = ($User->EmailAddress);
        @emails = ($User-&gt;EmailAddress);
        }
    }
   
        # remove duplicates
    # remove duplicates
        my %temp = (); @emails = grep ++$temp{$_} < 2, @emails;
    my %temp = (); @emails = grep ++$temp{$_} &lt; 2, @emails;
        send_report(@emails);
    send_report(@emails);
    }
}
   
   
    # Close RT Handle
# Close RT Handle
    $RT::Handle->Disconnect();
$RT::Handle-&gt;Disconnect();
    exit 0;
exit 0;
   
    # This procedure will send a report by mail to the owner
# This procedure will send a report by mail to the owner
    #  parameter 1 - email addresses to send to
#  parameter 1 - email addresses to send to
    # Global variables refered to:
# Global variables refered to:
    #  $subject - Subject line
#  $subject - Subject line
    #  @report - Message content
#  @report - Message content
    #  $from_address - address to send from
#  $from_address - address to send from
    sub send_report {
sub send_report {
        my @tos = @_;
    my @tos = @_;
        my $addr;
    my $addr;
   
        foreach $addr (@tos) {
    foreach $addr (@tos) {
            next if (length($addr) == 0);
        next if (length($addr) == 0);
            my $msg = "";
        my $msg = "";
            $msg .= "From: $from_address\n";
        $msg .= "From: $from_address\n";
            $msg .= "To: $addr\n";
        $msg .= "To: $addr\n";
            $msg .= "Subject: $subject\n";
        $msg .= "Subject: $subject\n";
            $msg .= "\n";
        $msg .= "\n";
            $msg .= $report;
        $msg .= $report;
   
            if ($debug) {
        if ($debug) {
                print "====== Would call '$sendmail' with this input:\n";
            print "====== Would call '$sendmail' with this input:\n";
                print "$msg\n\n";
            print "$msg\n\n";
      } else {
} else {
                open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
            open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
                print SENDMAIL $msg;
            print SENDMAIL $msg;
                close(SENDMAIL);
            close(SENDMAIL);
      }
}
        }
    }
    }
}
   
   
</nowiki>


== Old version ==
== Old version ==
Line 426: Line 422:
====== Version by Tomas Borland Valenta added at 14.3.2007 ======
====== Version by Tomas Borland Valenta added at 14.3.2007 ======


<nowiki>#!/usr/bin/perl -w
    ####################### RT Email Notification Script ####################
####################### RT Email Notification Script ####################
    ####
####
    #### Author: Daniely Yoav / Qball Technologies Ltd.
#### Author: Daniely Yoav / Qball Technologies Ltd.
    #### Email: yoavd@qballtech.net
#### Email: yoavd@qballtech.net
    #### Date: 05/06/05
#### Date: 05/06/05
    ####
####
    #### Modified by: Tomas Borland Valenta
#### Modified by: Tomas Borland Valenta
    #### Email: tomas at trustica dot cz
#### Email: tomas at trustica dot cz
    #### Date: 2007/03/12
#### Date: 2007/03/12
    ####
####
    #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
#### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
    ####
####
    #### Version: 2
#### Version: 2
    #### Changes from 1.2
#### Changes from 1.2
    #### - rewriten mail subsystem
#### - rewriten mail subsystem
    #### - code cleanup
#### - code cleanup
    #### - adopted for RT 3.6.x
#### - adopted for RT 3.6.x
    #### - used some global RT config variables
#### - used some global RT config variables
    ####
####
    ####  Usage: Invoke via cron every working day at 8 morning
####  Usage: Invoke via cron every working day at 8 morning
    ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl
####  0 8 * * 1-5 /path/to/script/remind_email_due.pl
   
    ### External libraries ###
### External libraries ###
    use strict;
use strict;
    use lib ("/usr/share/request-tracker3.6/lib");
use lib ("/usr/share/request-tracker3.6/lib");
    package RT;
package RT;
    use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
    use RT::Date;
use RT::Date;
    use RT::Queue;
use RT::Queue;
    use RT::Queues;
use RT::Queues;
    use RT::Tickets;
use RT::Tickets;
   
    ################## Init ##################
################## Init ##################
    # Clean our environment
# Clean our environment
    CleanEnv();
CleanEnv();
    # Load the RT configuration
# Load the RT configuration
    RT::LoadConfig();
RT::LoadConfig();
    RT::Init();
RT::Init();
    # Set config variables
# Set config variables
    my $debug=0;
my $debug=0;
    my $from_address = $RT::CorrespondAddress; #From: address used in reports
my $from_address = $RT::CorrespondAddress; #From: address used in reports
    my $rt_url = $RT::WebURL;
my $rt_url = $RT::WebURL;
    my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
    ################## Variables Init ##################
################## Variables Init ##################
    my $User = new RT::User($RT::SystemUser); # Define an RT User variable
my $User = new RT::User($RT::SystemUser); # Define an RT User variable
    my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
    my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
    my $now = new RT::Date($RT::SystemUser); # get current time
my $now = new RT::Date($RT::SystemUser); # get current time
    $now->SetToNow();
$now-&gt;SetToNow();
    my $report; # Used for output
my $report; # Used for output
    my $subject; # Used as subject line
my $subject; # Used as subject line
   
    ################## Main Program ##################
################## Main Program ##################
    # Limit the ticket search to new and open only.
# Limit the ticket search to new and open only.
    $tickets->LimitStatus(VALUE => 'new');
$tickets-&gt;LimitStatus(VALUE =&gt; 'new');
    $tickets->LimitStatus(VALUE => 'open');
$tickets-&gt;LimitStatus(VALUE =&gt; 'open');
   
    # Loop through new/open tickets
# Loop through new/open tickets
    while (my $Ticket = $tickets->Next) {
while (my $Ticket = $tickets-&gt;Next) {
      # Construct POP-Up Message
  # Construct POP-Up Message
      $User->Load($Ticket->Owner);
  $User-&gt;Load($Ticket-&gt;Owner);
      # Compare Dates to check whether the ticket's due date is in the past + Due date exists
  # Compare Dates to check whether the ticket's due date is in the past + Due date exists
      $date->Set(Format => "ISO",Value => $Ticket->Due);
  $date-&gt;Set(Format =&gt; "ISO",Value =&gt; $Ticket-&gt;Due);
      if ($now->Unix - $date->Unix < 0 or $date->Unix == -1) { next; }
  if ($now-&gt;Unix - $date-&gt;Unix &lt; 0 or $date-&gt;Unix == -1) { next; }
      # Generate a report
  # Generate a report
      $report = "";
  $report = "";
      $report .= "Ticket #: " . $Ticket->id . "\n";
  $report .= "Ticket #: " . $Ticket-&gt;id . "\n";
      $report .= "Subject:  " . $Ticket->Subject . "\n";
  $report .= "Subject:  " . $Ticket-&gt;Subject . "\n";
      $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
  $report .= "Queue:    " . $Ticket-&gt;QueueObj-&gt;Name . " (". $Ticket-&gt;QueueObj-&gt;AdminCcAddresses .") \n";
      $report .= "Owner:    " . $User->Name ."\n";
  $report .= "Owner:    " . $User-&gt;Name ."\n";
      $report .= "Due date: " . $date->ISO . "\n";
  $report .= "Due date: " . $date-&gt;ISO . "\n";
      $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
  $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket-&gt;id . "\n";
      $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
  $subject =  "Ticket #". $Ticket-&gt;id . " with owner " . $User-&gt;Name ." is overdue";
   
      # Get Queue Admin CC
  # Get Queue Admin CC
      my @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
  my @emails = ($User-&gt;EmailAddress, split(/,/, $Ticket-&gt;AdminCcAddresses), split(/,/ , $Ticket-&gt;QueueObj-&gt;AdminCcAddresses));
      my %temp = (); @emails = grep ++$temp{$_} < 2, @emails; # remove duplicates
  my %temp = (); @emails = grep ++$temp{$_} &lt; 2, @emails; # remove duplicates
      send_report(@emails);
  send_report(@emails);
    }
}
    # Close RT Handle
# Close RT Handle
    $RT::Handle->Disconnect();
$RT::Handle-&gt;Disconnect();
    exit 0;
exit 0;
   
    # This procedure will send a report by mail to the owner
# This procedure will send a report by mail to the owner
    #  parameter 1 - email addresses to send to
#  parameter 1 - email addresses to send to
    # Global variables refered to:
# Global variables refered to:
    #  $subject - Subject line
#  $subject - Subject line
    #  @report - Message content
#  @report - Message content
    #  $from_address - address to send from
#  $from_address - address to send from
    sub send_report {
sub send_report {
      my @tos = @_;
  my @tos = @_;
      my $addr;
  my $addr;
   
      foreach $addr (@tos) {
  foreach $addr (@tos) {
        next if (length($addr) == 0);
    next if (length($addr) == 0);
        my $msg = "";
    my $msg = "";
        $msg .= "From: $from_address\n";
    $msg .= "From: $from_address\n";
        $msg .= "To: $addr\n";
    $msg .= "To: $addr\n";
        $msg .= "Subject: $subject\n";
    $msg .= "Subject: $subject\n";
        $msg .= "\n";
    $msg .= "\n";
        $msg .= $report;
    $msg .= $report;
        if ($debug) {
          print "====== Would call '$sendmail' with this input:\n";
    if ($debug) {
          print "$msg\n\n";
      print "====== Would call '$sendmail' with this input:\n";
        } else {
      print "$msg\n\n";
          open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
    } else {
          print SENDMAIL $msg;
      open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
          close(SENDMAIL);
      print SENDMAIL $msg;
        }
      close(SENDMAIL);
      }
    }
    }
  }
   
}
</nowiki>


== Old version ==
== Old version ==
Line 549: Line 542:
You can cut/paste or download the script from [http://qballtech.net/rt_3_remind_email_due.pl.gz Notifications script]. Put the script in your daily crontab (/etc/cron.daily on Fedora Core)
You can cut/paste or download the script from [http://qballtech.net/rt_3_remind_email_due.pl.gz Notifications script]. Put the script in your daily crontab (/etc/cron.daily on Fedora Core)


<nowiki>#!/usr/bin/perl -w
    ####################### RT Email Notification Script ####################
####################### RT Email Notification Script ####################
    #### Author: Daniely Yoav / Qball Technologies Ltd.
#### Author: Daniely Yoav / Qball Technologies Ltd.
    #### Email: yoavd@qballtech.net
#### Email: yoavd@qballtech.net
    #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
#### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
    #### Version: 1.1
#### Version: 1.1
    ####  Usage: Invoke via cron
####  Usage: Invoke via cron
    ####              */5 * * * * /path/to/script/remind_email_due.pl
####              */5 * * * * /path/to/script/remind_email_due.pl
    #### Date: 05/06/05
#### Date: 05/06/05
    ############################################################
############################################################
    my $from_address = 'reports@demo.qballtech.net'; #From: address used in reports
my $from_address = 'reports@demo.qballtech.net'; #From: address used in reports
    my $mail_host = 'localhost'; #Mail Server used for sending mail
my $mail_host = 'localhost'; #Mail Server used for sending mail
    my $my_host = 'demo.qballtech.net'; # My FQDN
my $my_host = 'demo.qballtech.net'; # My FQDN
    my $rt_url = 'https://demo.qballtech.net/rt';
my $rt_url = 'https://demo.qballtech.net/rt';
   
    # Days to send notifcations on
# Days to send notifcations on
    # Enable Debug
# Enable Debug
    my $debug=0;
my $debug=0;
    # initalize
# initalize
    use lib ("/usr/local/rt3/lib", "/usr/local/rt3/local/lib");
use lib ("/usr/local/rt3/lib", "/usr/local/rt3/local/lib");
    ############################################################
############################################################
    ################## DO NOT EDIT BELOW THIS LINE ##################
################## DO NOT EDIT BELOW THIS LINE ##################
    ################## External dependancies ##################
################## External dependancies ##################
    use strict;
use strict;
    use Carp;
use Carp;
    package RT;
package RT;
    use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
    use RT::Date;
use RT::Date;
    use RT::Queue;
use RT::Queue;
    use RT::Queues;
use RT::Queues;
    use RT::Tickets;
use RT::Tickets;
    use Mail::Internet;
use Mail::Internet;
    use Mail::Address;
use Mail::Address;
    use Net::SMTP;
use Net::SMTP;
    use Encode;
use Encode;
    use MIME::Base64;
use MIME::Base64;
    use MIME::QuotedPrint;
use MIME::QuotedPrint;
    use MIME::Words qw(:all);
use MIME::Words qw(:all);
   
    ################## RT Init ##################
################## RT Init ##################
    # Clean our environment
# Clean our environment
    CleanEnv();
CleanEnv();
    # Load the RT configuration
# Load the RT configuration
    RT::LoadConfig();
RT::LoadConfig();
    RT::Init();
RT::Init();
    ################## Variables Init ##################
################## Variables Init ##################
    my $User = RT::User->new($RT::SystemUser); # Define an RT User variable
  my $User = RT::User-&gt;new($RT::SystemUser); # Define an RT User variable
    my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
  my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
    my $pipe; # Used as PIPE to transfer data to smbclient
  my $pipe; # Used as PIPE to transfer data to smbclient
    my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
  my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
    my $now = new RT::Date($RT::SystemUser); # get current time
  my $now = new RT::Date($RT::SystemUser); # get current time
    $now->SetToNow();
  $now-&gt;SetToNow();
    my @report; # Used for output
  my @report; # Used for output
    my $subject; # Used as subject line
  my $subject; # Used as subject line
    ################## Main Program ##################
################## Main Program ##################
    # Limit the ticket search to new and open only.
# Limit the ticket search to new and open only.
    $tickets->LimitStatus(VALUE => 'new');
$tickets-&gt;LimitStatus(VALUE =&gt; 'new');
    $tickets->LimitStatus(VALUE => 'open');
$tickets-&gt;LimitStatus(VALUE =&gt; 'open');
    # Loop through new/open tickets
# Loop through new/open tickets
    while (my $Ticket = $tickets->Next) {
while (my $Ticket = $tickets-&gt;Next) {
        # Construct POP-Up Message
      # Construct POP-Up Message
        $User->Load($Ticket->Owner);
      $User-&gt;Load($Ticket-&gt;Owner);
        # Compare Dates to check whether the ticket's due date is in the past + Due date exists
      # Compare Dates to check whether the ticket's due date is in the past + Due date exists
        $date->Set(Format => "ISO",Value => $Ticket->Due);
      $date-&gt;Set(Format =&gt; "ISO",Value =&gt; $Ticket-&gt;Due);
        if ($now->Unix - $date->Unix  > 0 and $date->Unix != -1) {
      if ($now-&gt;Unix - $date-&gt;Unix  &gt; 0 and $date-&gt;Unix != -1) {
        # Generate a report
      # Generate a report
        @report = ();
      @report = ();
        push (@report,"Ticket #" . $Ticket->id . " is over his due date. \n");
      push (@report,"Ticket #" . $Ticket-&gt;id . " is over his due date. \n");
        push (@report,"Owner: " . $User->Name ."\n");
      push (@report,"Owner: " . $User-&gt;Name ."\n");
          push (@report,"Due date:" . $date->ISO . "\n");
        push (@report,"Due date:" . $date-&gt;ISO . "\n");
        push (@report,"Subject: " . $Ticket->Subject . "\n");
      push (@report,"Subject: " . $Ticket-&gt;Subject . "\n");
        push (@report,"URL: " . $rt_url . "/Ticket/Display.html?id=" . $Ticket->id . "\n");
      push (@report,"URL: " . $rt_url . "/Ticket/Display.html?id=" . $Ticket-&gt;id . "\n");
        push (@report,"\n\nTickets notifications script by Qball Solutions");
      push (@report,"\n\nTickets notifications script by Qball Solutions");
        push (@report,"\nplease report problems to solutions\@helpdesk.qballtech.net)");
      push (@report,"\nplease report problems to solutions\@helpdesk.qballtech.net)");
        push(@report,"\nContact us! (info\@qballtech.net)\n");
      push(@report,"\nContact us! (info\@qballtech.net)\n");
        $subject =  "Ticket #". $Ticket->id . " with Owner: " . $User->Name ." is over his due date\n";
      $subject =  "Ticket #". $Ticket-&gt;id . " with Owner: " . $User-&gt;Name ." is over his due date\n";
        #print $line .  "\n";
      #print $line .  "\n";
        #print $User->EmailAddress . "\n";
      #print $User-&gt;EmailAddress . "\n";
        # Send report by email
      # Send report by email
        # Get Queue Admin CC
      # Get Queue Admin CC
        send_report($User->EmailAddress . "," . $Ticket->AdminCcAddresses . "," .$Ticket->QueueObj->AdminCcAddresses);
      send_report($User-&gt;EmailAddress . "," . $Ticket-&gt;AdminCcAddresses . "," .$Ticket-&gt;QueueObj-&gt;AdminCcAddresses);
        print @report if $debug;
      print @report if $debug;
        }
      }
    }
}
    # Close RT Handle
# Close RT Handle
    $RT::Handle->Disconnect();
$RT::Handle-&gt;Disconnect();
    exit 0;
exit 0;
   
    sub send_report {
sub send_report {
    ##########################
##########################
    # Send report procedure###
# Send report procedure###
    ##########################
##########################
    # This procedure will send a report by mail to the owner
# This procedure will send a report by mail to the owner
    # Parameter 1) Email addresses to send to
# Parameter 1) Email addresses to send to
    # Global variables refered to:
# Global variables refered to:
    # $subject - Subject line
# $subject - Subject line
    # @report - Message content
# @report - Message content
    # $mail_host - mail relay host address
# $mail_host - mail relay host address
    # $from_address - address to send from
# $from_address - address to send from
    my $smtp;
my $smtp;
    my $addr;
my $addr;
    my $full;
my $full;
    my $to_address = "$_[0]";
my $to_address = "$_[0]";
    my @addrs = Mail::Address->parse("$to_address");
my @addrs = Mail::Address-&gt;parse("$to_address");
    my $mime_type = 'TEXT';
my $mime_type = 'TEXT';
    my $message = @report;
my $message = @report;
    foreach $addr (@addrs)
foreach $addr (@addrs)
    {
{
      $full=$addr->format;
  $full=$addr-&gt;format;
      $smtp = Net::SMTP->new($mail_host,Debug=> 0);
  $smtp = Net::SMTP-&gt;new($mail_host,Debug=&gt; 0);
      die "Couldn't connect to server" unless $smtp;
  die "Couldn't connect to server" unless $smtp;
      $smtp->mail( $from_address );
  $smtp-&gt;mail( $from_address );
      $smtp->to($full);
  $smtp-&gt;to($full);
      $smtp->data();
  $smtp-&gt;data();
      $smtp->datasend("Subject: $subject");
  $smtp-&gt;datasend("Subject: $subject");
      $smtp->datasend("To: " . $full . "\n");
  $smtp-&gt;datasend("To: " . $full . "\n");
      $smtp->datasend("From: " . $from_address . "\n");
  $smtp-&gt;datasend("From: " . $from_address . "\n");
      $smtp->datasend("\n");
  $smtp-&gt;datasend("\n");
      $smtp->datasend("@report\n");
  $smtp-&gt;datasend("@report\n");
   
      $smtp->dataend();
  $smtp-&gt;dataend();
      $smtp->quit();
  $smtp-&gt;quit();
    };
};
    }
}
</nowiki>

Latest revision as of 16:52, 8 January 2017

The following script will send email notifications on Tickets that are over due.

Notes by Barton: I ran this page through a sed script that fixed the formatting of the nowiki formatted code blocks. You are encouraged to check the history of this page and make sure that I didn't mess anything up.

New version ( 3.1 )

New version ( 3.1 ) by Vaclav Vobornik added at 4.7.2008

i made a cleaned version be subsituting < and > to < and >. this apperently got lost while moving from wikia to here.

also the preformatted text block syntax nowiki used below does not work here yet :(

find it here: http://pastebin.com/gj5R7wm2

   ####################### RT Email Notification Script ####################
   ####
   #### Author: Daniely Yoav / Qball Technologies Ltd.
   #### Email: yoavd@qballtech.net
   #### Date: 05/06/05
   ####
   #### Modified by: Tomas Borland Valenta
   #### Email: tomas at trustica dot cz
   #### Date: 2007/03/12
   ####
   #### Modified by: Tim Schaller
   #### Email: tim-rt@torzo.com
   #### Date: 2008/06/17
   ####
   #### Modified by: Vaclav Vobornik
   #### Email: vaclav dot vobornik at commerzbank dot com
   #### Date: 2008/07/04
   ####
   #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
   ####
   #### Version: 3.1
   ####
   #### Changes from 3 ( Vaclav Vobornik )
   #### - Added Cc and Bcc possibilities.
   ####
   #### Changes from 2 ( Tim Schaller )
   #### - Added multiple command line options.
   #### - Adaptive subject line.
   #### - Sending Admin CC emails optional.
   ####
   #### Changes from 1.2 ( Tomas Borland Valenta )
   #### - rewriten mail subsystem
   #### - code cleanup
   #### - adopted for RT 3.6.x
   #### - used some global RT config variables
   ####
   #### ======================================================================
   ####
   #### Command line options
   ####          -d          : turns dubugging on
   ####          -A          : Send to AdminCC ( made default not to )
   ####          -a       : Send reminders to tickets due in  or less days.
   ####                      : Includes overdue tickets.
   ####          -q   : Only send reminder for tickets in 
   ####          -o   : Only send reminders for tickets owned by 
   ####          -c   : Email in Cc
   ####          -b   : Email in Bcc
   ####
   #### ======================================================================
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue
   ####       : Remind them about tickets due in less then 5 days.
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue.
   ####       : Send copies to all AdminCC on the tickest.
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
   
   ### External libraries ###
   use strict;
   use Getopt::Std;
   
   use lib ("/opt/rt3/lib");  # Change this to your RT lib path!
   package RT;
   use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
   use RT::Date;
   use RT::Queue;
   use RT::Queues;
   use RT::Tickets;
   
   ################## Init ##################
   # Clean our environment
   CleanEnv();
   # Load the RT configuration
   RT::LoadConfig();
   RT::Init();
   # Set config variables
   my $debug=0;
   my $from_address = $RT::CorrespondAddress; #From: address used in reports
   my $rt_url = $RT::WebURL;
   my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
   ################## Args ##################
   my $queue         = ;
   my $owner         = ;
   my $advDate       = 0;
   my $secInDay      = 60*60*24;
   my $sendToAdminCC = 0;
   my $cc            = ;
   my $bcc           = ;
   
   my %options=();
   Getopt::Std::getopts("Ada:q:o:c:b:",\%options);
   
   $queue         = $options{q} if defined $options{q};
   $owner         = $options{o} if defined $options{o};
   $advDate       = ( $options{a} * $secInDay ) if defined $options{a};
   $debug         = $options{d} if defined $options{d};
   $sendToAdminCC =  $options{A} if defined $options{A};
   $cc            = $options{c} if defined $options{c};
   $bcc           = $options{b} if defined $options{b};
   
   
   ################## Variables Init ##################
   my $User = new RT::User($RT::SystemUser); # Define an RT User variable
   my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
   my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
   my $now = new RT::Date($RT::SystemUser); # get current time
   $now->SetToNow();
   my $report; # Used for output
   my $subject; # Used as subject line
   
   ################## Main Program ##################
   # Limit the ticket search to new and open only.
   $tickets->LimitStatus(VALUE => 'new');
   $tickets->LimitStatus(VALUE => 'open');
   
   # Loop through new/open tickets
   while (my $Ticket = $tickets->Next) {
       # Construct POP-Up Message
       $User->Load($Ticket->Owner);
   
       # Compare Dates to check whether the ticket's due date is in the past + Due date exists
       $date->Set(Format => "ISO",Value => $Ticket->Due);
       if ($now->Unix - $date->Unix < (1 - $advDate ) or $date->Unix == -1 or $date->Unix == 0) { next; }
   
       # Compare owner and queue if given. Skip current ticket if invalid.
       if ($owner) { if ( lc($User->Name) ne lc($owner) ) { next; } }
       if ($queue) { if ( lc($Ticket->QueueObj->Name) ne lc($queue) ) { next; } }
   
       # Generate a report
       $report = "";
       $report .= "Ticket #: " . $Ticket->id . "\n";
       $report .= "Subject:  " . $Ticket->Subject . "\n";
       $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
       $report .= "Owner:    " . $User->Name ."\n";
       $report .= "Due date: " . $date->ISO . "\n";
       $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
   
       # Set the subject based on the due date.
       if( ($now->Unix - $date->Unix < 0  ) or $date->Unix == -1 ) {
           $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is due on " . $date->ISO;
       } else {
           $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
       }
   
       # Get Queue Admin CC
       # Do we send to Admin CC as well as to owner?
       my @emails = ();
       if ( $sendToAdminCC ) {
           @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
       } else {
           @emails = ($User->EmailAddress);
       }
   
       # remove duplicates
       my %temp = (); @emails = grep ++$temp{$_} < 2, @emails;
       send_report(@emails);
   }
   
   # Close RT Handle
   $RT::Handle->Disconnect();
   exit 0;
   
   # This procedure will send a report by mail to the owner
   #  parameter 1 - email addresses to send to
   # Global variables refered to:
   #  $subject - Subject line
   #  @report - Message content
   #  $from_address - address to send from
   #  $cc - CarbonCoby email address
   #  $bcc - BlindCarbonCopy email address
   sub send_report {
       my @tos = @_;
       my $addr;
   
       foreach $addr (@tos) {
           next if (length($addr) == 0);
           my $msg = "";
           $msg .= "From: $from_address\n";
           $msg .= "To: $addr\n";
           $msg .= "Cc: $cc\n" if $cc;
           $msg .= "Bcc: $bcc\n" if $bcc;
           $msg .= "Subject: $subject\n";
           $msg .= "\n";
           $msg .= $report;
   
           if ($debug) {
               print "====== Would call '$sendmail' with this input:\n";
               print "$msg\n\n";
           } else {
               open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
               print SENDMAIL $msg;
               close(SENDMAIL);
           }
       }
   }
   
   
   

Old version ( 3.0 )

Version ( 3.0 ) by Tim Schaller added at 17.6.2008
   ####################### RT Email Notification Script ####################
   ####
   #### Author: Daniely Yoav / Qball Technologies Ltd.
   #### Email: yoavd@qballtech.net
   #### Date: 05/06/05
   ####
   #### Modified by: Tomas Borland Valenta
   #### Email: tomas at trustica dot cz
   #### Date: 2007/03/12
   ####
   #### Modified by: Tim Schaller
   #### Email: tim-rt@torzo.com
   #### Date: 2008/06/17
   ####
   #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
   ####
   #### Version: 3
   ####
   #### Changes from 2 ( Tim Schaller )
   #### - Added multiple command line options.
   #### - Adaptive subject line.
   #### - Sending Admin CC emails optional.
   ####
   #### Changes from 1.2 ( Tomas Borland Valenta )
   #### - rewriten mail subsystem
   #### - code cleanup
   #### - adopted for RT 3.6.x
   #### - used some global RT config variables
   ####
   #### ======================================================================
   ####
   #### Command line options
   ####          -d          : turns dubugging on
   ####          -A          : Send to AdminCC ( made default not to )
   ####          -a       : Send reminders to tickets due in  or less days.
   ####                      : Includes overdue tickets.
   ####          -q   : Only send reminder for tickets in 
   ####          -o   : Only send reminders for tickets owned by 
   ####
   #### ======================================================================
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -q SysAdmin
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue
   ####       : Remind them about tickets due in less then 5 days.
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -a 5 -q SysAdmin
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####       : and send notices to everyone in the SysAdmin Queue.
   ####       : Send copies to all AdminCC on the tickest.
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl -A -q SysAdmin
   
   ### External libraries ###
   use strict;
   use Getopt::Std;
   
   use lib ("/usr/local/rt/lib");  # Change this to your RT lib path!
   package RT;
   use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
   use RT::Date;
   use RT::Queue;
   use RT::Queues;
   use RT::Tickets;
   
   ################## Init ##################
   # Clean our environment
   CleanEnv();
   # Load the RT configuration
   RT::LoadConfig();
   RT::Init();
   # Set config variables
   my $debug=0;
   my $from_address = $RT::CorrespondAddress; #From: address used in reports
   my $rt_url = $RT::WebURL;
   my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
   ################## Args ##################
   my $queue         = ;
   my $owner         = ;
   my $advDate       = 0;
   my $secInDay      = 60*60*24;
   my $sendToAdminCC = 0;
   
   my %options=();
   Getopt::Std::getopts("Ada:q:o:",\%options);
   
   $queue         = $options{q} if defined $options{q};
   $owner         = $options{o} if defined $options{o};
   $advDate       = ( $options{a} * $secInDay ) if defined $options{a};
   $debug         = $options{d} if defined $options{d};
   $sendToAdminCC =  $options{A} if defined $options{A};
   
   ################## Variables Init ##################
   my $User = new RT::User($RT::SystemUser); # Define an RT User variable
   my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
   my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
   my $now = new RT::Date($RT::SystemUser); # get current time
   $now->SetToNow();
   my $report; # Used for output
   my $subject; # Used as subject line
   
   ################## Main Program ##################
   # Limit the ticket search to new and open only.
   $tickets->LimitStatus(VALUE => 'new');
   $tickets->LimitStatus(VALUE => 'open');
   
   # Loop through new/open tickets
   while (my $Ticket = $tickets->Next) {
       # Construct POP-Up Message
       $User->Load($Ticket->Owner);
   
       # Compare Dates to check whether the ticket's due date is in the past + Due date exists
       $date->Set(Format => "ISO",Value => $Ticket->Due);
       if ($now->Unix - $date->Unix < (1 - $advDate ) or $date->Unix == -1) { next; }
   
       # Compare owner and queue if given. Skip current ticket if invalid.
       if ($owner) { if ( lc($User->Name) ne lc($owner) ) { next; } }
       if ($queue) { if ( lc($Ticket->QueueObj->Name) ne lc($queue) ) { next; } }
   
       # Generate a report
       $report = "";
       $report .= "Ticket #: " . $Ticket->id . "\n";
       $report .= "Subject:  " . $Ticket->Subject . "\n";
       $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
       $report .= "Owner:    " . $User->Name ."\n";
       $report .= "Due date: " . $date->ISO . "\n";
       $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
   
       # Set the subject based on the due date.
       if( ($now->Unix - $date->Unix < 0  ) or $date->Unix == -1 ) {
           $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is due on " . $date->ISO;
       } else {
           $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
       }
       # Do we send to Admin CC as well as to owner?
       my @emails = ();
       if ( $sendToAdminCC ) {
           @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
       } else {
           @emails = ($User->EmailAddress);
       }
   
       # remove duplicates
       my %temp = (); @emails = grep ++$temp{$_} < 2, @emails;
       send_report(@emails);
   }
   
   
   # Close RT Handle
   $RT::Handle->Disconnect();
   exit 0;
   
   # This procedure will send a report by mail to the owner
   #  parameter 1 - email addresses to send to
   # Global variables refered to:
   #  $subject - Subject line
   #  @report - Message content
   #  $from_address - address to send from
   sub send_report {
       my @tos = @_;
       my $addr;
   
       foreach $addr (@tos) {
           next if (length($addr) == 0);
           my $msg = "";
           $msg .= "From: $from_address\n";
           $msg .= "To: $addr\n";
           $msg .= "Subject: $subject\n";
           $msg .= "\n";
           $msg .= $report;
   
           if ($debug) {
               print "====== Would call '$sendmail' with this input:\n";
               print "$msg\n\n";
      } else {
               open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
               print SENDMAIL $msg;
               close(SENDMAIL);
      }
       }
   }
   
   

Old version

Version by Tomas Borland Valenta added at 14.3.2007
   ####################### RT Email Notification Script ####################
   ####
   #### Author: Daniely Yoav / Qball Technologies Ltd.
   #### Email: yoavd@qballtech.net
   #### Date: 05/06/05
   ####
   #### Modified by: Tomas Borland Valenta
   #### Email: tomas at trustica dot cz
   #### Date: 2007/03/12
   ####
   #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
   ####
   #### Version: 2
   #### Changes from 1.2
   #### - rewriten mail subsystem
   #### - code cleanup
   #### - adopted for RT 3.6.x
   #### - used some global RT config variables
   ####
   ####  Usage: Invoke via cron every working day at 8 morning
   ####  0 8 * * 1-5 /path/to/script/remind_email_due.pl
   
   ### External libraries ###
   use strict;
   use lib ("/usr/share/request-tracker3.6/lib");
   package RT;
   use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
   use RT::Date;
   use RT::Queue;
   use RT::Queues;
   use RT::Tickets;
   
   ################## Init ##################
   # Clean our environment
   CleanEnv();
   # Load the RT configuration
   RT::LoadConfig();
   RT::Init();
   # Set config variables
   my $debug=0;
   my $from_address = $RT::CorrespondAddress; #From: address used in reports
   my $rt_url = $RT::WebURL;
   my $sendmail = "$RT::SendmailPath $RT::SendmailArguments";
   
   ################## Variables Init ##################
   my $User = new RT::User($RT::SystemUser); # Define an RT User variable
   my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
   my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
   my $now = new RT::Date($RT::SystemUser); # get current time
   $now->SetToNow();
   my $report; # Used for output
   my $subject; # Used as subject line
   
   ################## Main Program ##################
   # Limit the ticket search to new and open only.
   $tickets->LimitStatus(VALUE => 'new');
   $tickets->LimitStatus(VALUE => 'open');
   
   # Loop through new/open tickets
   while (my $Ticket = $tickets->Next) {
     # Construct POP-Up Message
     $User->Load($Ticket->Owner);
     # Compare Dates to check whether the ticket's due date is in the past + Due date exists
     $date->Set(Format => "ISO",Value => $Ticket->Due);
     if ($now->Unix - $date->Unix < 0 or $date->Unix == -1) { next; }
     # Generate a report
     $report = "";
     $report .= "Ticket #: " . $Ticket->id . "\n";
     $report .= "Subject:  " . $Ticket->Subject . "\n";
     $report .= "Queue:    " . $Ticket->QueueObj->Name . " (". $Ticket->QueueObj->AdminCcAddresses .") \n";
     $report .= "Owner:    " . $User->Name ."\n";
     $report .= "Due date: " . $date->ISO . "\n";
     $report .= "URL:      " . $rt_url . "Ticket/Display.html?id=" . $Ticket->id . "\n";
     $subject =  "Ticket #". $Ticket->id . " with owner " . $User->Name ." is overdue";
   
     # Get Queue Admin CC
     my @emails = ($User->EmailAddress, split(/,/, $Ticket->AdminCcAddresses), split(/,/ , $Ticket->QueueObj->AdminCcAddresses));
     my %temp = (); @emails = grep ++$temp{$_} < 2, @emails; # remove duplicates
     send_report(@emails);
   }
   # Close RT Handle
   $RT::Handle->Disconnect();
   exit 0;
   
   # This procedure will send a report by mail to the owner
   #  parameter 1 - email addresses to send to
   # Global variables refered to:
   #  $subject - Subject line
   #  @report - Message content
   #  $from_address - address to send from
   sub send_report {
     my @tos = @_;
     my $addr;
   
     foreach $addr (@tos) {
       next if (length($addr) == 0);
       my $msg = "";
       $msg .= "From: $from_address\n";
       $msg .= "To: $addr\n";
       $msg .= "Subject: $subject\n";
       $msg .= "\n";
       $msg .= $report;
       if ($debug) {
         print "====== Would call '$sendmail' with this input:\n";
         print "$msg\n\n";
       } else {
         open(SENDMAIL, "|$sendmail") || die "Error sending mail: $!";
         print SENDMAIL $msg;
         close(SENDMAIL);
       }
     }
   }
   

Old version

Daniely Yoav, !QBall Technologies Ltd. yoavd![at]qballtech![dot]net

You can cut/paste or download the script from Notifications script. Put the script in your daily crontab (/etc/cron.daily on Fedora Core)

   ####################### RT Email Notification Script ####################
   #### Author: Daniely Yoav / Qball Technologies Ltd.
   #### Email: yoavd@qballtech.net
   #### Purpose: Send Email Notification on all open/new tickets in RT that have their due date expired
   #### Version: 1.1
   ####  Usage: Invoke via cron
   ####               */5 * * * * /path/to/script/remind_email_due.pl
   #### Date: 05/06/05
   ############################################################
   my $from_address = 'reports@demo.qballtech.net'; #From: address used in reports
   my $mail_host = 'localhost'; #Mail Server used for sending mail
   my $my_host = 'demo.qballtech.net'; # My FQDN
   my $rt_url = 'https://demo.qballtech.net/rt';
   
   # Days to send notifcations on
   # Enable Debug
   my $debug=0;
   # initalize
   use lib ("/usr/local/rt3/lib", "/usr/local/rt3/local/lib");
   ############################################################
   ################## DO NOT EDIT BELOW THIS LINE ##################
   ################## External dependancies ##################
   use strict;
   use Carp;
   package RT;
   use RT::Interface::CLI qw(CleanEnv GetCurrentUser GetMessageContent loc);
   use RT::Date;
   use RT::Queue;
   use RT::Queues;
    use RT::Tickets;
   use Mail::Internet;
   use Mail::Address;
   use Net::SMTP;
   use Encode;
   use MIME::Base64;
   use MIME::QuotedPrint;
   use MIME::Words qw(:all);
   
   ################## RT Init ##################
   # Clean our environment
   CleanEnv();
   # Load the RT configuration
   RT::LoadConfig();
   RT::Init();
   ################## Variables Init ##################
    my $User = RT::User->new($RT::SystemUser); # Define an RT User variable
    my $date = new RT::Date($RT::SystemUser); # Define a date variable (used for comparisions)
    my $pipe; # Used as PIPE to transfer data to smbclient
    my $tickets = new RT::Tickets($RT::SystemUser); # Used to store Ticket search results
    my $now = new RT::Date($RT::SystemUser); # get current time
    $now->SetToNow();
    my @report; # Used for output
    my $subject; # Used as subject line
   ################## Main Program ##################
   # Limit the ticket search to new and open only.
   $tickets->LimitStatus(VALUE => 'new');
   $tickets->LimitStatus(VALUE => 'open');
   # Loop through new/open tickets
   while (my $Ticket = $tickets->Next) {
        # Construct POP-Up Message
        $User->Load($Ticket->Owner);
        # Compare Dates to check whether the ticket's due date is in the past + Due date exists
        $date->Set(Format => "ISO",Value => $Ticket->Due);
        if ($now->Unix - $date->Unix  > 0 and $date->Unix != -1) {
        # Generate a report
        @report = ();
        push (@report,"Ticket #" . $Ticket->id . " is over his due date. \n");
        push (@report,"Owner: " . $User->Name ."\n");
          push (@report,"Due date:" . $date->ISO . "\n");
        push (@report,"Subject: " . $Ticket->Subject . "\n");
        push (@report,"URL: " . $rt_url . "/Ticket/Display.html?id=" . $Ticket->id . "\n");
        push (@report,"\n\nTickets notifications script by Qball Solutions");
        push (@report,"\nplease report problems to solutions\@helpdesk.qballtech.net)");
        push(@report,"\nContact us! (info\@qballtech.net)\n");
        $subject =  "Ticket #". $Ticket->id . " with Owner: " . $User->Name ." is over his due date\n";
        #print $line .  "\n";
        #print $User->EmailAddress . "\n";
        # Send report by email
        # Get Queue Admin CC
        send_report($User->EmailAddress . "," . $Ticket->AdminCcAddresses . "," .$Ticket->QueueObj->AdminCcAddresses);
        print @report if $debug;
        }
   }
   # Close RT Handle
   $RT::Handle->Disconnect();
   exit 0;
   
   sub send_report {
   ##########################
   # Send report procedure###
   ##########################
   # This procedure will send a report by mail to the owner
   # Parameter 1) Email addresses to send to
   # Global variables refered to:
   # $subject - Subject line
   # @report - Message content
   # $mail_host - mail relay host address
   # $from_address - address to send from
   my $smtp;
   my $addr;
   my $full;
   my $to_address = "$_[0]";
   my @addrs = Mail::Address->parse("$to_address");
   my $mime_type = 'TEXT';
   my $message = @report;
   foreach $addr (@addrs)
   {
     $full=$addr->format;
     $smtp = Net::SMTP->new($mail_host,Debug=> 0);
     die "Couldn't connect to server" unless $smtp;
     $smtp->mail( $from_address );
     $smtp->to($full);
     $smtp->data();
     $smtp->datasend("Subject: $subject");
     $smtp->datasend("To: " . $full . "\n");
     $smtp->datasend("From: " . $from_address . "\n");
     $smtp->datasend("\n");
     $smtp->datasend("@report\n");
   
     $smtp->dataend();
     $smtp->quit();
   };
   }