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

Re: Re: Re: Re: Using MIME-Lite to send attachment

by rscott212 (Sexton)
on Apr 10, 2004 at 11:36 UTC ( [id://344115]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Using MIME-Lite to send attachment
in thread Using MIME-Lite to send attachment

Thank you for those suggestions. It works a little better without all those frames, but I'm still not getting all the text read. Oh well.

Another quick question. I think I've got the code about right, but now I'm getting the error message below. Any ideas?

C:\A\backup\scripts>mail_attach2.pl Bareword found where operator expected at C:\A\backup\scripts\mail_attach2.pl line 19, near "Filename =>'butterf +ly" (Might be a runaway multi-line '' string starting on line 18) (Do you need to predeclare Filename?) syntax error at C:\A\backup\scripts\mail_attach2.pl line 19, near "Fil +ename =>'butterfly" Bad name after ani' at C:\A\backup\scripts\mail_attach2.pl line 19.
Again, here is my code:
use MIME::Lite; ### Create a new multipart message: $msg = MIME::Lite->new( From =>'johns@mindspring.com', To =>'peter21458@aol.com', #Cc =>'some@other.com, some@more.com', Subject =>'A test with attachment', Type =>'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach(Type =>'TEXT', Data =>"Here's the file you wanted" ); $msg->attach(Type =>'animated cursor', Path =>'C:\a\cursors\', Filename =>'butterfly.ani' ); if ($I_DONT_HAVE_SENDMAIL) { MIME::Lite->send('smtp', "smtp.mailrelay.usps.gov", Timeout=>60) +; } $msg->send; ### will now use Net::SMTP as shown above #$text = $msg->as_string;
Thanks for all your help!

Rob

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Using MIME-Lite to send attachment
by tachyon (Chancellor) on Apr 10, 2004 at 13:27 UTC

    The error message actually pinpoints it for you. Problem on line 19.....Might be runaway line near '' on line >>>18<<<. The problem is that the \ char ESCAPES other characters so if you want a LITERAL \ you need to type \\ Note that single quotes and backslashes may cause you confusion. See fix below:

    # ***** This is the problem ***** # Path =>'C:\a\cursors\', # ***** This works, note \\ and double quotes " ***** Path => "C:\\a\\cursors\\",

    Note that \\ in Win32 is a pain. Unless you are executing stuff through the shell using backtics or system you can just use / ie open FILE, "C:/WINNT/system32/some.file" works just fine.

    With the error messages they look complex but the problem is usually trivial. Missing ; Forgetting to close quotes (or stating with " and ending with ' or vice versa) and missing braces { } are the most common culprits.

    cheers

    tachyon

      Hello. I have one more question. Thanks for all your help so far! I'm still having problems with this script. I think I have it all working except that I now get the error message:
      Can't call method "attach" without a package or object reference
      Can you tell me what this means?

      Rob

        What this means is pretty much what it says! You may well find adding the line 'use diagnostics;' to your code helpful as the diagnostics module will pull some details from the perldocs for you. For example:

        use diagnostics; 0->my_method(); __DATA__ Can't call method "my_method" without a package or object reference at (F) You used the syntax of a method call, but the slot filled by t +he object reference or package name contains an expression that retur +ns a defined value which is neither an object reference nor a package n +ame. Something like this will reproduce the error: $BADREF = 42; process $BADREF 1,2,3; $BADREF->process(1,2,3); Uncaught exception from user code: Can't call method "my_method" without a package or object referenc +e at script line 3

        So above you see an example that generates your error. Diagnostics have expanded the error message (in this case it is not the best explanation I have ever seen but....)

        So the error is I called the method 'my_method' on the value 0. You can't call a method on 0 or an undefined value or in fact anthing that is not a blessed object that supports that method. The error has occurred because your Mime::Lite object is not defined for some reason. Without seeing the code you are currently working with that is all I can say.

        cheers

        tachyon

        Here is an example that works on my Win32 box:

        use MIME::Lite; my $smtp = 'mail.trump.net.au'; # (typically your ISPs SMTP server) my $from = 'james.freeman@smartsurf.org'; my $to = $from; my @cc = qw( ); # add addresses here to Cc, space separated my $sbj = 'A test with attachment'; my @cc = ( "Cc" => (join ',', @cc) ) if @cc; my $msg = MIME::Lite->new( From => $from, To => $to, @cc, Subject => $sbj, Type =>'multipart/mixed', ) or die "Could not create Mime::Lite object!"; $msg->attach( Type =>'TEXT', Data =>"Here's the file you wanted" ); $msg->attach( Type =>'image/gif', # often 'application/octet-stre +am' Path =>"C:\\background.gif", # full path to file Filename =>'background.gif' # name we want to use in email +for file ); #print $msg->as_string; $msg->send_by_smtp( $smtp) or die "Could not send mail $!\n";

        cheers

        tachyon

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-25 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found