Or, just use MIME::Lite or another module which does these things for you :)

Cheers,
Kevin

On Tue, Nov 27, 2001 at 09:20:35AM -0600, Tomasi, Chuck ([EMAIL PROTECTED]) said 
something similar to:
> Here's one I can answer!  I agonized over this for weeks, but finally got a
> decent solution that I use every day!
> 
> For a binary file I would recommend "use MIME:Base64".  An example is
> provided.
> 
> Notes:
>       o You'll want to use multi-part MIME encoding (hence the use of
> MIME::Base64).  You could use quotable-printable, but you'll have to do some
> character translation and it gets yucky real fast.
>       o Take note that the filename is mentioned twice.  You can provide
> that any way you want.
>       o The number in $boundry is up to you.  Just make it unique and
> consistent throughout the message.  The number of dashes is fixed and must
> follow the format given.
>       o Change the path of sendmail to your own sendmail program.
> 
> ----------------------------------
> use MIME::Base64;
> 
>         open(F_MAIL, "|/usr/sbin/sendmail -t");
> 
>         $boundary="----------90125";
>         print F_MAIL <<END_OF_MAIL;
> Precedence: list
> From: $FROMUSER <$FROMEMAIL>
> To: $TOUSER <$TOEMAIL>
> MIME-Version: 1.0
> Subject: File attachment test
> Content-Type: multipart/mixed;
>         boundary=\"$boundary\"
> 
> This is a multi-part message in MIME format.
> 
> --$boundary
> Content-Type: text/plain;
>         charset=\"iso-8859-1\"
> 
> Here is the body of the message.  A file attachment is also provided below.
> 
> --$boundary
> Content-Type: application/octet-stream;
> name=\"somefile.doc\"
> Content-Transfer-Encoding: Base64
> Content-Disposition: attachment;
>         filename=\"somefile.doc\"
> 
> END_OF_MAIL
> 
> open(F_LOG, $LOGFILE) || &Error("Cannot open logfile for MIME encoding");
> while (read(F_LOG, $buf, 60*57)) {
>         print F_MAIL encode_base64($buf);
> }
> close(F_LOG);
> 
> print F_MAIL <<END_OF_MAIL;
> --$boundary--
> END_OF_MAIL
> 
>         close(F_MAIL);
> 

-- 
[Writing CGI Applications with Perl - http://perlcgi-book.com]
Deserve it (death)! I daresay he does. Many that live deserve death. And some t
hat die deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the wise cannot see all end.
        -- Gandalf (Fellowship of the Ring)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to