bldsystemtools/commonbldutils/record_delivery.pm
changeset 0 83f4b4db085c
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 package record_delivery;
       
     2 
       
     3 =head1 NAME
       
     4 
       
     5 Record delivery
       
     6 
       
     7 =head1 SYNOPSIS
       
     8 
       
     9 record_delivery.pl
       
    10 
       
    11 =head1 DESCRIPTION
       
    12 
       
    13 This module is designed to send an email for the purpose of recording deliveries.
       
    14 
       
    15 =head1 COPYRIGHT
       
    16 
       
    17 Copyright (c) 2005 Symbian Ltd. All rights reserved
       
    18 
       
    19 =cut
       
    20 
       
    21 =over 4
       
    22 
       
    23 =item * Template Notes
       
    24 
       
    25 The basic rules of the template for creating a delivery record are:-
       
    26 The replacement sections as per HTML::Template module rules.
       
    27 %% is a seperator
       
    28 Spelling and case of words is critical
       
    29 General line format is:- Field name in Delivery record document%%Field value%%
       
    30 No line returns will be transferred to the delivery record document
       
    31 "Responsible Person" can only be a single person.
       
    32 "Symbian Contact" and "Additional Email List" can be multiple people seperated by a semicolon (;)
       
    33 "Consignee Name" and "Contract Identifier" are values chosen from the deliveries database
       
    34 No empty fields are allowed, to simulate an empty field use a single space
       
    35 All the fields shown in the example must be present.
       
    36 
       
    37 e.g
       
    38 Title%%<TMPL_VAR NAME=BuildNumber> CBR Delivery to Kshema%%
       
    39 Export Controlled%%Yes%%
       
    40 Reason Why Not Exported%% %%
       
    41 Consignee Name%%Kshema Technologies%%
       
    42 Contract Identifier%%N/A system Test 07/08/2003%%
       
    43 Recipient Email%%Andrew.Beck@Symbian.com%%
       
    44 Recipient Project%% %%
       
    45 Additional Email List%% %%
       
    46 Symbian Contact%%Monika Lewandowski; Denis Lyons%%
       
    47 Responsible Person%%Monika Lewandowski%%
       
    48 Source/Archive Location%%\\builds01\ODCBuilds\CBR_Archive_<TMPL_VAR NAME=BuildShortName>%%
       
    49 Notification Email text%%This is a test 2 of auto delivery recording%%
       
    50 Delivery Notes%%GT_Techview_Baseline Version <TMPL_VAR NAME=BuildNumber and GT_Only_Baseline Version <TMPL_VAR NAME=BuildNumber>%%
       
    51 
       
    52 =back
       
    53 
       
    54 =over 4
       
    55 
       
    56 =item * Other Notes
       
    57 
       
    58 An email will be sent back to the from_address value if the creation of the
       
    59 record delivery document fails.
       
    60 
       
    61 =cut
       
    62 
       
    63 use 5.6.1;
       
    64 use strict;
       
    65 use warnings;
       
    66 
       
    67 use Exporter;
       
    68 use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS @EXPORT_FAIL);
       
    69 @ISA = ('Exporter');
       
    70 @EXPORT = qw(new send);
       
    71 @EXPORT_FAIL = qw ();
       
    72 %EXPORT_TAGS = ( ':all' =>[qw/new send/] );
       
    73 $VERSION = '0.1';
       
    74 
       
    75 use Carp;
       
    76 use Net::SMTP;
       
    77 use Sys::Hostname;
       
    78 use HTML::Template;
       
    79 
       
    80 sub new
       
    81 {
       
    82 	my ($class) = shift;
       
    83   our %args = @_;
       
    84 	my $self = {};
       
    85 	bless $self, $class;
       
    86 	
       
    87 	# Use config file if defined
       
    88 	if (defined $args{'config_file'})
       
    89 	{
       
    90 		# populate %args from file
       
    91 		do $args{'config_file'};
       
    92 	}
       
    93 	
       
    94 	# if from address is not set then the from is the machine name
       
    95 	if(!defined($args{'from_address'}))
       
    96 	{
       
    97 		$self->{'from_address'} = hostname;
       
    98 	} else {
       
    99 		$self->{'from_address'} = $args{'from_address'};
       
   100 	}
       
   101 
       
   102 	# if to address is not set then confess
       
   103 	if(!defined($args{'to_address'}))
       
   104 	{
       
   105 		confess "ERROR: Sending email, no To: address defined";
       
   106 	} else {
       
   107 		$self->{'to_address'} = $args{'to_address'};
       
   108 	}
       
   109 
       
   110 	# if to smtp_server is not set then set it to the local machine
       
   111 	if(!defined($args{'smtp_server'}))
       
   112 	{
       
   113 		$self->{'smtp_server'} = hostname;
       
   114 	} else {
       
   115 		$self->{'smtp_server'} = $args{'smtp_server'};
       
   116 	}
       
   117 
       
   118 
       
   119   return $self;
       
   120 }
       
   121 
       
   122 sub send
       
   123 {
       
   124   
       
   125   my $self = shift;
       
   126 
       
   127   my %args = @_;
       
   128 	
       
   129 	# Create the Template and allow supplied params not to exist in the template
       
   130   my $email = new HTML::Template(filename => $args{'Template'}, die_on_bad_params => 0);
       
   131 	# Delete the template filename from the %args hash so a generic loop can be
       
   132 	# used for other Template Variables where the key is the same as TMPL_VAR NAME
       
   133 	delete $args{'Template'};
       
   134 	
       
   135 	#Complete Template
       
   136 	foreach my $key (keys %args)
       
   137 	{
       
   138 		$email->param($key => $args{$key});
       
   139 	}
       
   140 
       
   141   
       
   142   my (@message);
       
   143 
       
   144   push @message,"From: $self->{'from_address'}\n";
       
   145   push @message,"To: $self->{'to_address'}\n";
       
   146   push @message,"Subject: Auto Import\n";
       
   147   push @message,"\n";
       
   148   push @message,$email->output();
       
   149 
       
   150   my $smtp = Net::SMTP->new($self->{'smtp_server'}, Hello => hostname, Debug   => 0);
       
   151   $smtp->mail();
       
   152   $smtp->to($self->{'to_address'});
       
   153 
       
   154   $smtp->data(@message) or confess "ERROR: Sending email";
       
   155   $smtp->quit;
       
   156   
       
   157 }
       
   158 
       
   159 1;