From: Kelly J. <ke...@vm...> - 2000-10-29 17:54:02
|
What I'm looking for right now is to forward faxes by e-mail as they come in - they're .bfx files, probably an obscure proprietary format. I was hoping there might be a way to attach any binary file for flexibility. I found the bit of Perl code below on the web, but it wants to have sendmail 0.75 installed, which I don't think you're using, and which might be redundant. Thanks, Kelly #!perl -w # # Name: # Mail-Sendmail-Attachment-Demo.pl. # # Parameters: # 1 The 'To' address. Eg: ro...@sa.... # 2 The name of the file to attach. Eg: C:/Temp/file.txt. # # Authors: # Milivoj Ivkovic <mi...@al...> # # Ron Savage <ro...@sa...> # # Home: # http://savage.net.au/Perl-tutorials.html (tutorial # 2) # # Note: # Mail::Sendmail does not require MS Windows. # I've only used MS Windows to set $smtp and $from. # # Reference: # http://alma.ch/perl/Mail-Sendmail-FAQ.htm. use integer; use strict; use MIME::QuotedPrint; use MIME::Base64; use Mail::Sendmail 0.75; # doesn't work with v. 0.74! use Config; BEGIN { require 'win32-Mail-Lib.pl' if ($Config{'osname'} eq 'MSWin32'); } # ----------------------------------------------------------------- my($to) = shift || die("Usage: $0 <To> <AttachmentFileName>\n"); my($fileName) = shift || die("Usage: $0 <To> <AttachmentFileName>\n"); my($smtp, $from); if ($Config{'osname'} eq 'MSWin32') { ($smtp, $from) = &getSMTPFrom(); } else { ($smtp, $from) = ('milky.way.com', 'ro...@sa...'); } die('SMTP server name not found') if (! $smtp); die('Sender name not found') if (! $from); my(%mail) = ( SMTP => $smtp, From => $from, To => $to, Subject => "Mail-Sendmail-Attachment-Demo.pl", ); my($boundary) = "====" . time() . "===="; $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; my($message) = encode_qp("$fileName is attached"); open(F, $fileName) or die("Cannot read $fileName: $!\n"); binmode F; { undef $/; $mail{body} = encode_base64(<F>); } close F; $boundary = '--'.$boundary; $mail{body} = <<END_OF_BODY; $boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable $message $boundary Content-Type: application/octet-stream; name="$fileName" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="$fileName" $mail{body} $boundary-- END_OF_BODY sendmail(%mail) || die("Error: $Mail::Sendmail::error\n"); print "OK. Log says:\n", $Mail::Sendmail::log; # Success. print "Success \n"; exit(0); Visionary Media, Inc. tel 415-927-6636 x 101 fax 415-927-6636 |