Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

email attachments using multipart MIME format

by waiterm (Acolyte)
on Sep 22, 2003 at 18:11 UTC ( #293216=perlquestion: print w/replies, xml ) Need Help??

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

can someone tell me why, when i try to send an e-mail using MIME lite it keeps on returning 'no data in this part'. The attachment exists, code is as follows

#!c:\Perl\bin\perl5.8.0.exe # Rob Waite 09/2003 # generate AVS data from Helpful Holidays use CGI; use Sprite; use LWP::Simple; use DBI; use Time::Local; use File::Copy; use MIME::Lite; use LWP::UserAgent; $ua = new LWP::UserAgent; $timeout = 60; # *************************** get descriptions & photos ******** +*********************** # &get_date; &desc; # &get_star; # &array_onde; # &get_AVS; # &email; $ondefile = "C:/tmp/onde.txt"; sub desc { $logfile = "C:/tmp/HHOL/LOG.".$$; $property = 1; &get_date; open(HHOL, "C:/tmp/HHOL/HHOL.txt") || die ("unable to open HHOL fi +le"); while(my @HHOLid = split /=[^\n]*\n/, <HHOL>) { foreach $HHOLid (@HHOLid) { print ("Property $property: $HHOLid \n"); $tmp = "C:/tmp/HHOL/Text/HHOL-".$HHOLid.".txt"; $src = "". +$HHOLid."&year=".$year; sleep (rand 10); $_ = get($src); $star_ = $_; if ($_ =~ /No Active/) { print ("$HHOLid does not exist on Helpful Holidays\n") +; open(LOG,">>$logfile"); print LOG "Proprty: ".$HHOLid." does not exist on Help +ful Holidays\n"; close LOG; } else { $pic_ = $_; @dat = split(/Provisionally book this Property">/, $_) +; $_ = $dat[1]; @dat = split(/<\/DIV>/i, $_,); $_ = $dat[0]; $_ =~ s/<[^>]*>//g; $_ =~ s/\s/ /g; $_ =~ s/ / /gs; $_ =~ s/ +//gs; $_ =~ s/\&[^\;]*\;//g; $_ =~ s/\.\.\. a/\n\nA/g; $_ =~ s/\.\.\.a/\n\nA/g; $_ =~ s/\.\.\. b/\n\nB/g; $_ =~ s/\.\.\. /\n\n/g; $_ =~ s/ / 0.5 /g; $_ =~ s/|./.5 /g; $_ =~ s/ / 0.25 /g; $_ =~ s/|./.25 /g; $_ =~ s/ / 0.75 /g; $_ =~ s/|./.75 /g; $_ =~ s/ \././g; $_ =~ s/ ,/,/g; $_ =~ s/ \;/;/g; $_ =~ s/'|'/'/g; $_ =~ s/"|"/"/g; if (@dat = split(/Other properties/,$_)) { $_ = $dat[0]; } &star; open (TD, ">$tmp"); print TD "Star rating: ".$star."\n +\nSleeps: ".$sleeps."\n\nBedrooms: ".$beds."\n\n".$_."\n\nChangeover +Day: ".$change."\n\nThese star ratings are unique in that they rely e +normously heavily on the experience of the inspectors, members of our + staff who have seen hundreds of houses. They check everything we can + think might be relevant to your holiday enjoyment, from basic cleanl +iness to whether the colour of the curtains goes with the duvet cover +s, and then they grade the property on the basis of all of these thin +gs. They remain, however, strictly personal assessments, in the best +of faith, of interior quality and ambience only. They have nothing to + do with the outward appearance or situation. Nor are they necessaril +y directly related to the quality or quantity of 'gadgets'. Tick boxe +s ? ... well, some, yes, but mostly it's about ambience, tone and com +fort, all looked at with a good dollop of common sense.\n\nProperties + rated 5 star now would have been miles off the scale 10 years ago an +d as standards continue to charge upwards we constantly review to ens +ure that our star ratings remain useful. The greatest praise of them +is, perhaps, the degree to which our customers of many years tell us +they rely on our star ratings ABOVE ALL ELSE in their search for a pe +rfect holiday place. The fact they have been appreciated by so many p +eople for so many years makes us feel we are doing something right.\n +\n1 Star means what we would call 'basic', i.e. it has all the basic +necessities but contains little or nothing that is new or smart. Howe +ver, it may well have charm. A surprising number of people say 'basic +' is what they want.\n\n2 Star is better furnished and equipped: ofte +n very pleasant, quite attractive and friendly - just a little old fa +shioned. Or, alternatively, more functional than beautiful.\n\n3 Star + good quality and thoroughly efficient, a considerable and successful + effort made to make it attractive; well-equipped; almost always fitt +ed kitchens.\n\n3 and a half Stars means better quality.\n\n4 Star me +ans excellent, 'own home' feeling, very good quality, attractive and +well furnished and probably (though not necessarily - see individual +descriptions) extremely well-equipped; or in some other way special.\ +n\n4 and a half Star means all that and more.\n\n5 Star means excepti +onal.\n\nMore people say we malign places than that we over-rate them +. And please don't forget 1 and a half and 2 Star properties may be +in marvellous situations."; close TD; &email; @pics = split(/Additional Pictures and Videos:/, $pic_ +, 2); $pic_ = $pics[1]; @pics = split(/<img src="media\//, $pic_, 2); $pic_ = $pics[1]; @pics = split(/.jpg" /, $pic_, 2); $tp = $pics[0]; $str = "\"$tp\", \"\","; $count = 1; while ($count < 5) { $pic_ = $pics[1]; @pics = split(/<img src="media\//, $pic_, 2); $pic_ = $pics[1]; @pics = split(/.jpg" /, $pic_, 2); $pic_ = $pics[0]; if ($pic_ ne "") { $str = $str." \"".$pic_."\", -".$count.","; } $count++; } %letter = eval($str); while (($lett, $num) = each(%letter)) { $tmp2 = "C:/tmp/HHOL/Pics/HHOL-".$HHOLid.$num.".jp +g"; $pic = "".$le +tt.".jpg"; print ("$pic\n"); sleep (rand 15); getstore($pic, $tmp2); # if (open($tmp2)) { # &emailpics; # } } } } $property++; die "Just a test\n"; } } sub email { $filename = "HHOL-".$HHOLid.$num.".jpg"; print ("$filename\n"); $msg = MIME::Lite->build( From => '', To => '', Subject => 'HC 0', Type => 'Multipart/mixed'); $msg->attach( Type => 'text image/jpg', Path => $tmp2, Filename => $filename, Disposition => 'attachment'); $msg->send('smtp', ""); } sub emailpics { $filename = "HHOL-".$HHOLid.".txt"; $msg = MIME::Lite->build( From => '', To => '', Subject => 'HC 0', Type => 'Multipart/mixed'); $msg->attach( Type => 'text file/txt', Path => $tmp, Filename => $filename, Disposition => 'attachment'); $msg->send('smtp', ""); }

janitored by ybiC: Balanced <readmore> tags around loooong code block

Replies are listed 'Best First'.
Re: email attachments using multipart MIME format
by demerphq (Chancellor) on Sep 22, 2003 at 18:39 UTC

    You arent passing parameters around so its hard to see the actual code flow. Im betting its because $tmp2 isnt assigned a variable when &email is called. (Although the error message is on the face of it a bit confusing.) Ill look at making MIME::Lite a little more intelligent in this regard. But you might consider turning on strict and warnings. By the time you have cleaned up your code enough to make Perl stop whining I suspect this matter will be resolved. :-)


    Everybody remember the Gandhi quote?

      First they ignore you, then they laugh at you, then they fight you, then you win.

    Gentlemen and ladies, this newest leaked memo from Microsoft confirms that we are advancing through GandhiCon Three.

      I've managed to fix the problem, basically my checks to see whether the files existed weren't working properly, I've changed it to a simpler
      if (-e $tmp) { $picfilename = "".$AGENT."-".$AGENTid.".jpg"; print ("$pic +filename\n"); $msg->attach( Type => 'image file/jpg', Path => $tmp, Filename => $picfilename, Disposition => 'attachment'); }
      I've also altered where it creates the extra parts to the e-mail, so for each property it creates an e-mail, adds each part in the loop if the file exists and then sends the e-mail. Thanks very much for your help, I'm glad I managed to find the monks, especially after the amount of times I've been getting stuck in my learning recently!
Re: email attachments using multipart MIME format
by clscott (Friar) on Sep 22, 2003 at 19:18 UTC

    Please reduce your code sample to the smallest possible chunk that still demonstrates your problem.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-07-07 05:02 GMT
Find Nodes?
    Voting Booth?

    No recent polls found