Dr. Mario Sanchez wrote: > dear perl gurus > > i *have* to use a hosting service that does not have/allow Mime::Lite so > i am pretty much stuck with the classic sendmail. but i need to send > attachments. the hosting service is godaddy - i mention them not to > denigrate but in case someone else found a solution with this hosting > service. <code> > though i tried in vain, how can i attach either a binary file or a text > file using sendmail?
If they allow Net::SMTP you can do something like: # Net::SMTP: send attachment using Net::SMTP use strict; use warnings; use Net::SMTP; use MIME::Base64; # email if you need a substitute base64 my $file = $ARGV[0] || 'some.gif'; # file to attach my $ct = 'image/gif'; # content type for attachment my $smtphost = '192.168.4.106'; # SMTP mail host my $from = 'kbar...@americallgroup.com'; my $to = 'kbar...@americallgroup.com'; # get the GIF my $content; { local $/ = undef; # slurp file open IN, $file or die "Error opening $file: $!"; binmode IN; $content = <IN>; close IN; } # skip encode if using text my $encode = encode_base64 ($content); # base 64 encode it my $boundary = '<------------ FUBAR: '; my @chrs = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z'); foreach (0..16) { $boundary .= $chrs[rand (scalar @chrs)]; } $boundary .= ' ------------>'; my $msg = <<EOD; From: $from To: $to Reply-To: $from Subject: Test image attach to Net::SMTP MIME-Version: 1.0 X-Mailer: fubar.pl Content-Type: multipart/mixed; boundary="$boundary" This is a multipart MIME-coded message --$boundary Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Attached is a GIF file. --$boundary Content-Type: $ct; name="$file" Content-Disposition: inline; filename="$file" Content-Transfer-Encoding: base64 $encode --$boundary-- EOD my $smtp = Net::SMTP->new($smtphost, Debug => 1) or die "Net::SMTP::new: $!"; $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend($msg); $smtp->dataend(); exit; __END__ Without Net::SMTP, something like this might do ya: open MAIL, "|/usr/lib/sendmail -t"; print MAIL <<EOD; To: $destination From: $sender Subject: Consultant Hours Worked Submission MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="<-----Some Garbage [$$] --------->" --<-----Some Garbage ---------> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Attached is an .rtf file from work. (or whatever) --<-----Some Garbage ---------> Content-Type: application/rtf; name="$txtfile" Content-Transfer-Encoding: base64 $encode <this is a base 64 encoded file if binary> --<-----Some Garbage --------->-- EOD close MAIL; } __END__ _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs