in reply to Sending a email with file attachment with LWP ONLY

I think you need to start by clarifying some terms. What do you mean by MIME and MAIL? There are no modules by those names that I know of, though there are several in those namespaces. Is your customer opposed to all of them, or just certain ones?

It's true that LWP understands the mailto: protocol, so it may be able to send a composed message for you. I'm really not sure how mailto through HTTP works, and I'd be surprised if you can count on it working with every web server. But even if it does, first you have to compose the message, and if the message is going to have attachments, you need MIME. That's what MIME is for. It encodes the file so it can pass through 7-bit SMTP, puts it in a standard wrapper, and adds headers to tell mail clients how to decode it.

In the olden days, we sent files through email without MIME, by doing things like this:

$ uuencode <me.gif | mail -s 'My Picture' friend@somewhere.com

Then the friend would cut the encoded text out of the message and pass it through uudecode to get the original file. But there was no standard, and you had to do it all manually outside your mail client. MIME developed to standardize and automate the process.

You could still do something like that today, but only if you're controlling both ends so you know how to decode your encodings. A client who wants to send attachments to anyone but says you can't use MIME, is like a client who hires you to drive nails but says you can't use a hammer. He'd better have a really good reason. Without knowing that reason, it's hard to suggest what would be an acceptable alternative.

Aaron B.
Available for small or large Perl jobs; see my home node.

Replies are listed 'Best First'.
Re^2: Sending a email with file attachment with LWP ONLY
by tobyink (Canon) on Jul 05, 2012 at 13:36 UTC

    "It's true that LWP understands the mailto: protocol, so it may be able to send a composed message for you. I'm really not sure how mailto through HTTP works, and I'd be surprised if you can count on it working with every web server."

    LWP's support for "mailto:" URIs doesn't involve HTTP at all - it just invokes /usr/sbin/sendmail and sends the mail that way. Similarly when LWP is passed a "file:" URI, it will happily read the file off your local system without any HTTP anywhere.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Thanks for the correction. The LWP man page just said the message is "passed on to the mail system," and since it's formatted just like a POST HTTP request, I didn't know if that was on the local system or a remote one as in a more typical HTTP request. I didn't see how it could possibly work reliably through a web server, but didn't want to make too many assumptions. Since sendmail isn't available on all systems, that seems like a fairly brittle way to do it, when there are other mail modules that will talk SMTP as well.

      Aaron B.
      Available for small or large Perl jobs; see my home node.