在winnt/win9x下用blat發email的示例(轉)

post0發表於2007-08-10
在winnt/win9x下用blat發email的示例(轉)[@more@]

#

# 步驟:

#

# A.安裝blat.

# 1.下載blat .( )

# 2. 解壓到一個目錄,如 e:usrbinblat

#

# B.除錯本程式.

#

### 配置信件內容 ##

$blat_prog="e:usrinlatlat.exe"; #指定blat.exe路徑

$server="smtp.263.net";

$from="sirbowl@263.net";

$to="sirbo@263.net";

$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:

#

# 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 blazer@mail.nevalink.ru

# 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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章