sub SendMail { my ($Html_File) = @_ ; my ($From_Addr, $To_Addr, $Cc_Addr, $Subject, $From_Address, $Msg_Body, $Email_From); $Email_From = $Sql_Globals::Email_From ; $From_Addr = $Sql_Globals::From_Addr ; $From_Address = "$Email_From <$From_Addr>"; $Subject = $Sql_Globals::Subject ; $To_Addr = $Sql_Globals::To_Addr ; $Cc_Addr = $Sql_Globals::Cc_Addr ; $Msg_Body = $Sql_Globals::Msg_body ; chomp($Subject); chomp($Cc_Addr); chomp($To_Addr); chomp($From_Address); &Connect_SMTP_Server; print "From_Address : $From_Address\n"; print "To_Address : $To_Addr\n"; print "Cc_Addr : $Cc_Addr\n"; print "Message : $Msg_Body\n"; print "File : $Html_File\n"; my $returncode = $main::SMTP_OBJ->MailFile({ from => qq($From_Address), #From address to => qq($To_Addr), #To address cc => qq($Cc_Addr), #Cc address subject => qq($Subject), #Subject of the Email msg => qq($Msg_Body), #Body message of the Email file => qq($Html_File) #Filename to attach }); print "Return Status : $returncode\n"; if ( ref($returncode) eq "Mail::Sender" ) { print "\n".localtime()."Email Sent.............\n"; &DisConnect_SMTPServer; } else{ print "\n".localtime()."Email Sending Failed.............\n"; print "$Mail::Sender::Error\n"; &DisConnect_SMTPServer; } } sub Connect_SMTP_Server { my $SMTP_Server_Details = &Get_SMTP_Details; my $SMTP_Obj; my($SMTP_ServerIP, $SMTP_Port, $SMTP_UserName,$SMTP_Password) = @$SMTP_Server_Details; print "SMTP Server IP:$SMTP_ServerIP,Username:$SMTP_UserName,Password:$SMTP_Password\n"; ##SMTP server details unless(!$SMTP_ServerIP || !$SMTP_UserName ){ while(1){ ##Create object for Mail::Sender program $SMTP_Obj = Mail::Sender->new ( { 'smtp' => qq($SMTP_ServerIP), 'debug' => q(/tmp/Emaildebug.err), 'authid' => $SMTP_UserName, 'authpwd' => $SMTP_Password, }); ##Check connection succeed or failed if (ref ($SMTP_Obj) ne 'Mail::Sender'){ ##Log error message if Not able to connect to SMTP server print "\n".localtime()."CONNECT ERROR: Unable to connect to Mailhost $SMTP_ServerIP"; print "\n".localtime()."..............Try Again after 15 seconds......."; sleep(15); } else{ print "\n"."=" x 80; print "\n".localtime()." : SMTP Server Connected Successfully.......\n"; $main::SMTP_OBJ= $SMTP_Obj; print ">>>$main::SMTP_OBJ<<<\n"; last; } } } else{ print "SMTP Server details are not available."; print "Exiting the program........\n"; exit(0); } } unless(@ARGV){ print "\n\tGive File name as argument\n\n"; } else{ my $file = $ARGV[0]; print "$file"; &SendMail($file); }