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

> -----Original Message-----
> From: paul beckett (JIC) [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 27, 2001 5:41 AM
> To: [EMAIL PROTECTED]
> Subject: Send e-mail attachment
> Importance: High
> 
> 
> Does anybody know how I can send a smallish binary file as an e-mail
> attachment, from perl (running on UNIX (OSFv.4.0))
> 
> Thanks
> 
> Paul
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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

Reply via email to