View Full Version : PERL - Do you have what it takes?
KarmaComa
04-05-2000, 01:22 PM
OK I'm trying to send an email with an attachment with a perl script from winNT, but the most success I've had so far is an email with the 'attached' file in the body.
I've tried several modules, and they all do the same thing. Has anyone done this? Can anyone help?
CurtC
04-05-2000, 02:09 PM
You don't mention how you're trying to do it, whether piping output to sendmail, or using a module.
There are lots of mail modules available at http://www.perl.com/reference/query.cgi?mail - it looks like Mail::Sendmail will let you send attachments (of limited size).
KarmaComa
04-05-2000, 02:22 PM
Well it looks like I have to use a module, since I'm in NT.
handy
04-05-2000, 08:51 PM
Arent perl scripts just ASCII text? Ive got some why not just email them as text?
Joe_Cool
04-05-2000, 11:15 PM
Originally posted by KarmaComa:
...I'm in NT.
Looks like we found your problem! ;)
------------------
Joe Cool
-----
Full speed, right ahead
Don't stop, you can sleep when you're dead
mrblue92
04-06-2000, 10:55 AM
What's the nature of the error?
Can you zip the script and send it compressed?
KarmaComa
04-06-2000, 11:43 AM
Uh.. you guys misunderstand. I need to attach a file to an email WITH a perl script, not attach a perl script to an email.
Yes one of the problems is being in NT.
All the perl modules I can find just send the file as part of the message body, which is useless to me. If it doesn't show up as a paper clip in Outlook, then it's no good to me. I COULD do it in UNIX, but the only mail programs available are mail and mailx.
Let me rephrase the question: does anyone know how to send a bona fide email attachment from a command line? (Either UNIX or NT, I'm getting to the point where I don't care anymore).
KarmaComa
04-06-2000, 01:21 PM
MIME::Lite requires sendmail, which I do not have. If you do use MIME:Lite, do you know if it will send a proper attachment (i.e. paper clip in Outlook)?
I even downloaded blat, a dos command line mailer, and that shoves the file into the message body, too!
Perderabo
04-06-2000, 01:28 PM
et me rephrase the question: does anyone know how to send a bona fide email
attachment from a command line? (Either UNIX or NT, I'm getting to the point where I
don't care anymore).
I really did test that script. It really did work.
http://boards.straightdope.com/ubb/Forum3/HTML/007114.html
Hunsecker
04-06-2000, 01:36 PM
Actually, I haven't used MIME::Lite, I just read the readme on cpan. So I don't know how the attachments will show up in outlook, but I would be very surprised if outlook couldn't handle mime enclosures (i get the feeling I may be giving MS too much credit though).
You may want to see if you can get the Mail::Sendmail (http://cpan.valueclick.com/modules/by-category/19_Mail_and_Usenet_News/Mail/) package to work (it claims platform independence). You may be able to compose the message using MIME::Lite, then send the text it generates to Mail::Sendmail.
Other than that, I don't know of any command line programs that will do it.
mrblue92
04-06-2000, 03:54 PM
Well, do you have sendmail on your UNIX box? I've got an include file I use in Progress (a 4GL database language) to do exactly what you're talking about. Even if you aren't using Progress, the logic is only about 40 lines of codes and pretty understandable. I can post or e-mail it if you'd like. (YMMV)
mrblue92
04-06-2000, 04:13 PM
Oops... I just noticed you already said you didn't have sendmail on your UNIX... Bummer; it won't work for you then.
You could try inserting the MIME boundaries in the text of your message around your file (in your Perl script as Hunsecker suggested), but it'll start getting a little messy if you try send something other than a text file. In the case of binaries, you'd probably need to incorporate an encoding algorithm. (I've never needed to do binaries in this method.)
KarmaComa
04-06-2000, 04:16 PM
Perderabo: I tried your script and it gave me:
Ignoring recipients on command line with -t
Then let me input the text... it ignored the recipient, which I had (obviously) defined with a -t then -a.... and didn't send it to anyone. Why does it ignore this?
To the other person: I would love your code.. any ideas would help. My email is adking@uvic.ca. Thanks.
And thanks everyone for your continued assistance.
Hunsecker
04-07-2000, 12:26 AM
You could have your script write out the mime tags directly I guess. So following the subject line, write:
Mime-Version: 1.0
Content-Type: multipart/mixed ; boundary="<put some unique text here to seperate the parts of the message, my mailer usually puts in the encoded date or something>"
--<that unique text from above>
Content-Type: text/plain; charset=us-ascii
message body
--<that unique text from above>
Content-Type: image/jpeg
Content-Description: someimage.jpg
Content-Transfer-Encoding: base64 (or uuencode or something)
repeat for each part of the message, then:
--<that unique text from above>--
(That oughtta work, I've had to muck directly with mime tags a few times but it usually ended up being trial and error)
Or, you could check www.cpan.org (http://www.cpan.org) for a MIME module for perl. Theres gotta be one out there.
Hunsecker
04-07-2000, 12:39 AM
Aah, and indeed there is a module on cpan.
MIME::Lite (http://cpan.valueclick.com/modules/by-category/15_World_Wide_Web_HTML_HTTP_CGI/MIME/) looks like it'll do what you want, and looks real easy too.
handy
04-07-2000, 10:24 AM
try cgi-resources.com they have anything & everything to do for it....should have just what you need for NT.
WhiteNight
04-07-2000, 06:15 PM
Can you get a win32 UUEncode or Base64Encode program? If so, encode the file to attach. Then output the raw mime headers, the encoded file, and the mime footers. Should be fairly simple.
RFC 1521 describes MIME (It says it's part 1, so there's likely more.)
http://www.oac.uci.edu/indiv/ehood/MIME/1521/rfc1521ToC.html
That should explain how to form the headers.
If you're in doubt, grab the linux source for sendmail/etc and see how they did it.
Hunsecker
04-07-2000, 06:23 PM
Just FYI, when I was poking around in CPAN earlier, I noticed that MIME: :Decoder would also do encodings for a data stream.
Might be easier and safer than running an external program.
Hunsecker
04-07-2000, 09:59 PM
Damn smileys. Thats MIME::Decoder of course.
mrblue92
04-14-2000, 11:00 AM
Any luck, KC?
KarmaComa
04-14-2000, 11:08 AM
No.. I tried messing around with MIME headers, editing perl modules, etc., but then said screw it, because it's not something that has to be done.
vBulletin® v3.7.3, Copyright ©2000-2013, Jelsoft Enterprises Ltd.