在winnt/win9x下用blat发email的示例(转)[@more@]
#
# 步骤:
#
# A.安装blat.
# 1.下载blat .( http://gepasi.dbs.aber.ac.uk/softw/Blat.html )
# 2. 解压到一个目录,如 e:usrbinblat
#
# B.调试本程序.
#
### 配置信件内容 ##
$blat_prog="e:usrinlatlat.exe"; #指定blat.exe路径
$server="smtp.263.net";
$from="
[email protected]";
$to="
[email protected]";
$subject="hi,this is sent from blat.exe !";
$body="this is body!!!!";
###### 配置完成 ########
$file=""; #一般为空
$temp_files_path="."; #一般为空
##############
($errcode,$output) = &mail_blat($blat_prog, $server, $from, $to, $subject, $file, $body, $temp_files_path);
&htmlhead;
print " errcode is $errcodeoutput is $output";
exit;
#########################
sub htmlhead{
local($temp1)=$_[0];
if($has_send != 1){
if($temp1 eq "admin"){
print "Content-type: text/htmln";
print "Pragma:no-cachenn";
}else{
print "Content-type: text/htmlnn";
}
$has_send=1;
}
}
########
# 以下一段是库文件的函数说明
#=====================================================================
#
# Sending mail with Blat (Win 95/NT)
#
# Blat home page: http://gepasi.dbs.aber.ac.uk/softw/Blat.html
#
# Can send file or text or file+text (if both $file and $body ne "")
#
# Call as:
# ($errcode,$output)=
# &mail_blat($blat_prog, $server, $from, $to,
# $subject, $file, $body, $temp_files_path);
#
# Returns error-code(correct in Blat 1.5 only) and Blat-output
#
# Author : Mike Blazer
[email protected]
# Version: 1.4 Last Modified: Jan 7, 1998
# Tested : on ActiveWare's Perl port, build 110; Win'95, Win NT+IIS 3.0
#=====================================================================
sub mail_blat {
local ($blat_prog, $SMTP_host, $from, $to, $subj,
$file, $body, $temp_files_path) = @_;
local ($temp_file, $out, $filebody);
if (!$body){
return 4,"Both body/file sources are empty in " .
__FILE__." at line ".__LINE__."n" if !$file;
$temp_file=$file;
}
else {
# create temp-file's name
BEGIN{ srand $$.time }
do {$temp_file = "$temp_files_path/".
int (rand(1000000)).".file"} until (!-e $temp_file);
# file+body request
if ($file) {
open (IN,"$file") ||
return 1,"Can not read file $file in " .
__FILE__." at line ".__LINE__."n";
$filebody = join "",;
close IN;
}
# write message's body to temp-file
open (TEMP, ">$temp_file") ||
return 2,"Can not write temp-file $file in " .
__FILE__." at line ".__LINE__."n";
print TEMP "$filebodyn$body";
close TEMP;
} # end of else
$out=`$blat_prog $temp_file -s "$subj" -f $from -t $to -server
$SMTP_host`;
# remove temp-file
unlink $temp_file if ($temp_file ne $file);
# workaround syntax error that returns 0
$? = 3 if(!$? && $out=~/nsyntax:n/);
# return error-code and Blat-output
return $?,$out;
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8225414/viewspace-942997/,如需转载,请注明出处,否则将追究法律责任。