vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I have written the following Email sending program with attachment. When I run this program manually from my linux terminal Email goes with attachment. When I put this script in the crontab, Empty file is get attached, its happening only for this xls file, I am getting the HTML and TXT files
What could be the issue?
sub SendMail { my ($Html_File) = @_ ; my ($From_Addr, $To_Addr, $Cc_Addr, $Subject, $From_Address, $Msg_Bo +dy, $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) = @$SM +TP_Server_Details; print "SMTP Server IP:$SMTP_ServerIP,Username:$SMTP_UserName,Passwor +d:$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 M +ailhost $SMTP_ServerIP"; print "\n".localtime()."..............Try Again after 15 seco +nds......."; 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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Unable to send the xls attachment file with the Mail::Sender
by mrguy123 (Hermit) on Nov 21, 2011 at 07:28 UTC | |
by vinoth.ree (Monsignor) on Nov 21, 2011 at 08:42 UTC | |
by mrguy123 (Hermit) on Nov 21, 2011 at 11:53 UTC | |
Re: Unable to send the xls attachment file with the Mail::Sender
by jmcnamara (Monsignor) on Nov 21, 2011 at 13:25 UTC | |
by mrguy123 (Hermit) on Nov 21, 2011 at 14:45 UTC | |
by vinoth.ree (Monsignor) on Nov 22, 2011 at 10:10 UTC | |
by Ravi V (Scribe) on Sep 26, 2012 at 12:08 UTC |
Back to
Seekers of Perl Wisdom