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); }

In reply to Unable to send the xls attachment file with the Mail::Sender by vinoth.ree

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.