Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

MIME::Lite

by TStanley (Canon)
on Jul 24, 2000 at 21:26 UTC ( [id://24130]=perlquestion: print w/replies, xml ) Need Help??

TStanley has asked for the wisdom of the Perl Monks concerning the following question:

I am attempting to send an email message with an attached text file.
Here is the code that creates the file in question:

if($#ARGV==-1) { #use current date $date='date--d'1 day ago'+'%Y-%m-%d''; chop($date); } else { print"USAGE: summary.pl[date yyyy-mm-dd]\n"; } $rptname="summary".$date.".txt"; print"Date: ",$date,"\n"; print"Report: ",$rptname,"\n"; open(RPT,">$rptname")||warn "Unable to open report file: $!\n";

And here is the code that should send me the attached file.
The name of the file should be (in this case): summary2000-07-23.txt


use MIME::Lite; $msg=MIME::Lite->new( From =>'root@localhost.mycompany.com', To =>'myname@mycompany.com', Subject =>'Summary Report', Type =>'multipart/mixed'); $msg->attach(Type =>'TEXT', Data =>"Summary Report for yesterday"); $msg->attach(Type =>'TEXT', Path =>'$rptname', Filename =>'summary'.$date.'.txt'); $msg->send;


However, when I run this program, I don't receive anything in my mailbox.
Any ideas? TStanley

Replies are listed 'Best First'.
RE: MIME::Lite
by young perlhopper (Scribe) on Jul 24, 2000 at 22:18 UTC
    Everything looks pretty reasonable, so you should probably check the return values (i.e. $!) of the functions as you call them. At the very least do:

    $msg->send or die "couldn't send!!!";

    Then, when you know which function call fails, the answer may be immediately obvious, or at the very least the monks will have a little more to go on. (if all the calls succeed i would say take a good look at your mail server)

    Good Luck,
    Mark

      I added the "or die" to the end of the send function. No luck there.
      It seems like it is actually sending the message, but not going anywhere.
      I do know that our sendmail actually works, so it could possibly be that
      MIME::Lite needs configuring, although I have no clue as to how to go about it.

      Thanks for the help though

      TStanley
        You need to check the return codes from ALL your function calls. For all you know, the new failed and you're calling all the other methods on a null function.

        Always check your return codes.

        *Woof*

Re: MIME::Lite
by le (Friar) on Jul 24, 2000 at 23:19 UTC
    First, your method of getting the date isn't very "perlish". I'd done this:
    my ($day, $month, $year) = (localtime)[3,4,5]; $year += 1900; $month += 1; if ($month < 10) { $month = "0" . $month; } $day--; # We want yesterdays date, yeah? Ok, this fails for the first +of the month, I don't have the time to hack that :) my $date = "$year-$month-$day";
    (Besides that: did you copy and paste the code snippets? If yes, then you won't have a date at all, if I understand your code right, you tried to use backticks to get the date, but I can see just plain quotes.)

    And what happens if you change the second "attach" type to "text/plain"?
      The $day-- doesn't look so good.
      It will be much easier and safer to use Time::Local

      quoting from there:
      use Time::Local 'timelocal_nocheck'; { # The 365th day of 1999 print scalar localtime timelocal_nocheck 0,0,0,365,0,99; # The twenty thousandth day since 1970 print scalar localtime timelocal_nocheck 0,0,0,20000,0,70; # And even the 10,000,000th second since 1999! print scalar localtime timelocal_nocheck 10000000,0,0,1,0, +99; }
      Another option is to subtract 60*60*24 from the epoch time and use that.

      Cheers.
Re: MIME::Lite
by redmist (Deacon) on Jul 24, 2000 at 23:44 UTC
    One problem may be that you are using the logical or operator in list context where there are precedence issues (at least with die). Try using or instead.

    open(RPT,">$rptname")||warn "Unable to open report file: $!\n";

    should be:
    open(RPT, ">$rptname") or warn "Unable to open report file: $!\n";


    redmist
    redmist.dyndns.org
    redmist@users.sourceforge.net

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://24130]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-12-02 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found