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

Dealing with atachments.

by Punto (Scribe)
on May 17, 2000 at 10:59 UTC ( [id://12062]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

Hi.. I'm writting the scripts for a "free e-mail" site (I hate those sites), and I have troubles taking care of 2 things:

- the delivery of the e-mails (I'm looking in sendmail.org for that)
- the attachments.

So: how could I handle the attachments in perl? Is there a module? does it have easy documentation with nice examples? :-)

also: is there any open souce solution for that, so I don't have to do anyrthing? :-)

Thanks..

Replies are listed 'Best First'.
Re: Dealing with atachments.
by lhoward (Vicar) on May 17, 2000 at 11:24 UTC
    For dealing with attachments use one of the perl MIME modules. I find that MIME::Lite has been strong-enough to do anything I've ever needed with attachments/multipart messages. Here's an example of its usage taken from the MIME::Lite documentation:
    use MIME::Lite; # Create a new multipart message: $msg = new MIME::Lite From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed'; # Add parts (each "attach" has same arguments as "new"): attach $msg Type =>'TEXT', Data =>"Here's the GIF file you wanted"; attach $msg Type =>'image/gif', Path =>'aaa000123.gif', Filename =>'logo.gif';
    Once you have your message constructed with attachments then you need to send it. I prefer to use Net::SMTP to send messages, but there are several other perl modules that can send mail (and several ways of just doing it by hand). If you're already using MIME::Lite the easiest method is to use its built-in send function:
    $msg->send;
    If you're interested in delving deeper, O'Reilly has a decent book entitled Programming Internet Email that covers most of the interesting internet e-mail protocols and formats. It has a good chapter on e-mail related Perl modules.
      That a good example.. thanks..
      And, can I use that module if I get the attachment, to convert it to a file?

      Thanks..

        MIME::Lite can only encode MIME streams. For decoding a MIME message you'll want to use the MIME::Decoder module.
        I just posted this snippet which should help you with decoding and extracting attachments from incoming emails.
RE: Dealing with atachments.
by BBQ (Curate) on May 17, 2000 at 14:43 UTC
    > also: is there any open souce solution for that, so I don't have to do anyrthing?

    You probably already know this, but there are quite a few people out there that make this same mistake: Being Open Source'd does not imply that you'll have everything done for you. As a matter of fact, it usually implies that you should do some of the work yourself so that others can benefit from it too! I hate being such a rant, but I've seen freeware, open source, and GPL mistaken and mixed quite a few number of times. (Haven't we all?)

    #!/home/bbq/bin/perl
    # Trust no1!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://12062]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.