Re: Sending Mail from Script: Setting Header
On Fri, 20 Oct 2006 11:23:26 +0200, Ronald Fischer wrote:
>
> So before I try one of these, I would like to ask what approach other
> users use to easily send mail using attachments from a script. A
> solution
> working on shell level would be preferable, but different approaches
> in Perl, Ruby, Tcl or Python would also be interesting.
I used perl because of the different files I send to people in my
humor list. perl snippet follows: (indention dinked up to fit usenet rules)
if ($_lc_fn =~ /\.txt/i)
{ $_type = 'text/plain' ; $_encode = 0 ; last SWITCH ; }
if ($_lc_fn =~ /\.swf/i)
{ $_type = 'application/octet-stream' ; $_encode = 1 ; last SWITCH ; }
if ($_lc_fn =~ /\.eml/i)
{ $_type = 'multipart/related' ; $_en code = 0 ; last SWITCH ; }
if ($_lc_fn =~ /\.wmv/i)
{ $_type = 'video/x-ms-asf' ; $_encod e = 1 ; last SWITCH ; }
if ($_lc_fn =~ /\.zip/i)
{ $_type = 'application/x-zip-compres sed' ; $_encode = 1 ; last SWITCH ;
}
if ($_type eq "unknown" )
{
printf "unknown sufix file type on $_fn_to_send\n" ;
exit 1 ;
}
if ( $_encode == 0)
{
$msg = MIME::Lite->new(
From =>"$USER\@$HOSTNAME",
To =>$_to,
Subject =>"$_subject $_type bytes=$size",
Type =>$_type,
Path =>$_fn_to_send
);
}
else
{
$msg = MIME::Lite->new(
From =>"$USER\@$HOSTNAME",
To =>$_to,
Subject =>"$_subject $_type bytes=$size",
Type =>$_type,
Encoding =>'base64',
Path =>$_fn_to_send
);
}
open MAIL, "|/usr/sbin/sendmail.postfix -t -oi -oem" or
die "Error on mailopen is: $!\n";
$msg->print(\*MAIL);
close MAIL;
|