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