I'd use MIME::Tools, it works really well. You just need to know where sendmail is located, postfix installs its own version of it which is compatible. Here's some code I use all the time:
use strict;
use vars qw/$cmdMail/;
use LWP::MediaTypes qw(guess_media_type read_media_types);
use MIME::Entity;
BEGIN {
$cmdMail='/usr/lib/sendmail'; # location of your sendmail
read_media_types('/etc/mime.types'); # location of your mime.types
+ file
}
...
sub sendmail { # returns undef or error
my ($from,$to,$subject,$body,@attachments)=@_;
my $ret;
my $top=build MIME::Entity
From => $from,
'Reply-to' => $from,
To => $to,
Subject => $subject,
Data => $body;
if (@attachments) {
for my $path (@attachments) {
my $type=guess_media_type($path);
$top->attach(
Path => $path,
Type => $type,
Encoding => '-SUGGEST'
);
}
}
$top->sync_headers(Length=>'COMPUTE') if @attachments;
if (open(MAIL,"| $cmdMail -t -i")) {
$top->print(\*MAIL);
close MAIL;
} else {
$ret="Mail to $to failed: $!";
}
$ret;
}
...
my $err=sendmail('server@wacky.com','programmer@wacky.com','Your turke
+y is done!',"Come get some! Don't forget the beer!",'/home/programme
+r/Pictures/beer.jpg');
die $err if $err;
...
HTH,
SSF |