PERL - Do you have what it takes?

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?

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).

Well it looks like I have to use a module, since I’m in NT.

Arent perl scripts just ASCII text? Ive got some why not just email them as text?

Looks like we found your problem! :wink:


Joe Cool

Full speed, right ahead
Don’t stop, you can sleep when you’re dead

What’s the nature of the error?

Can you zip the script and send it compressed?

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).

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 for a MIME module for perl. Theres gotta be one out there.

Aah, and indeed there is a module on cpan.

MIME::Lite looks like it’ll do what you want, and looks real easy too.

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!

I really did test that script. It really did work.
http://boards.straightdope.com/ubb/Forum3/HTML/007114.html

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 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.

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)

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.)

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.

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.

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.

Damn smileys. Thats MIME::Decoder of course.

try cgi-resources.com they have anything & everything to do for it…should have just what you need for NT.

Any luck, KC?