如何实现ASP的文件上载和EMAIL的发送?(150分)

S

smilboy

Unregistered / Unconfirmed
GUEST, unregistred user!
如何实现ASP的文件上载和EMAIL的发送?请举例越细越好,我只知道上载可用PSHOST。DLL但不会用
 
X

xWolf

Unregistered / Unconfirmed
GUEST, unregistred user!
用ASP发电子邮件

ASP Source Code: 源代码:

--------------------------------------------------------------------------------
<%
Dim strTo, strSubject, strBody 'Strings for recipient, subject, boby
Dim objCDOMail 'The CDO object

'First we'll read in the values entered
strTo = Request.Form("to")
'These would read the message subject and body if we let you enter it
'strSubject = Request.Form("subject")
'strBody = Request.Form("body")
strSubject = "Sample E-mail sent from ASP 101!"
' This is multi-lined simply for readability
strBody = "This message was sent from a sample at http://www.asp101.com. "
strBody = strBody &amp;
"It is used to show people how to send e-mail from an "
strBody = strBody &amp;
"Active Server Page. If you did not request this "
strBody = strBody &amp;
"e-mail yourself, your address was entered by one of "
strBody = strBody &amp;
"our visitors. Wedo
not store these e-mail addresses."
strBody = strBody &amp;
" Please address all concerns to webmaster@asp101.com."
'Ok we've got the values now on to the point of the script.
'We just check to see if someone has entered anything into the to field.
'If it's equal to nothing we show the form, otherwise we send the message.
'If you weredo
ing this for real you might want to check other fields too
'anddo
a little entry validation like checking for valid syntax etc.
If strTo = "" then
%>
<FORM ACTION="./email_cdo.asp" METHOD="post">
Enter your e-mail address:<BR>
<INPUT TYPE="text" NAME="to" SIZE="30"></INPUT>
<!-- These would be used if we decided to let you edit them
Subject:&amp;nbsp;
<INPUT TYPE="text" NAME="subject" SIZE="30"></INPUT><BR>

Message:&amp;nbsp;
<TEXTAREA NAME="body" ROWS="10" COLS="40" WRAP="virtual"></TEXTAREA><BR>
-->
<INPUT TYPE="submit" VALUE="Send Mail!"></INPUT>
</FORM>
<%
else
' Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")

' Set the properties of the object
objCDOMail.From = "webmaster@asp101.com"
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.Body = strBody
' There are lots of other properties you can use.
' You can send HTML e-mail, attachments, etc...
' You can also modify most aspects of the message
' like importance, custom headers, ...
' Check thedo
cumentation for a full list as well
' as the correct syntax.
' Some of the more useful ones I've included samples of here:
'objCDOMail.Cc = "john@asp101.com;gary@asp101.com"
'objCDOMail.Bcc = "john@asp101.com;gary@asp101.com"
'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)
'objCDOMail.AttachFile "c:/path/filename.txt", "filename.txt"
' Send the message!
objCDOMail.Send

' Set the object to nothing because it immediately becomes
' invalid after calling the Send method.
Set objCDOMail = Nothing
Response.Write "Message sent to " &amp;
strTo &amp;
"!"
End If
%>
 
X

xWolf

Unregistered / Unconfirmed
GUEST, unregistred user!
用ASP发电子邮件: 不好意思,看看源码吧.
编写功能完备的ASP文件上载组件
——对“编写Web方式上载文件的ASP组件”一文的补充
中国人民武装警察部队学院
马民
---- 黄明建的“编写Web方式上载文件的ASP组件”(以下简称原文)一文从RFC1867标准出发,分析了上传的二进制文件格式,编写出了具有文件上载功能的ASP组件,突破了多以Perl语言来实现WEB方式上载文件的方法。但原文忽略了以下几个关键问题:
按照RFC1867标准,上载的文件可以更换新名。在原文的demo.htm中,文本框text1即起到保存新文件名的作用。原文却忽略了这一点,使得text1成为一个并无实际意义的元素;
ActiveX代码部件(ASP组件)的接口函数(类的公有成员函数)是强类型检查,即必须指定形参的具体数据类型而不能使用自动类型(Variant);但在ASP环境中,所有的变量实际上都是Variant类型,如何使ASP的变量可以作为ASP组件接口函数的实参将关系到ASP组件是否具有实际的应用价值。原文也忽略了这一技术要点;
ASP组件毕竟是基于服务器端的,诸如空提交等的验证应首先在客户端采用VBScript/JavaScript来完成,以避免无用信息的传递。
---- 基于以上几点,本文首先升级了原文的ASP组件版本,使其成为一个功能完备的ASP文件上载组件。
---- 现将原文ASP组件中接口的规范说明总结如下:
---- 1、 功能:取得提交表单中元素的值;
---- 方法名:GetTheValue;
---- 形参:提交表单中元素名称,nm(数据类型:字符串);
---- 返回值:成功,则为指定的元素在提交表单中的值(数据类型:字符串);
----------- 失败,则返回零长度字符串。
---- 2、 功能:保存上载文件
---- 方法名:SaveTheFile
---- 形参:1、提交表单中文件类型元素名称,strTag(数据类型:字符串);
--------- 2、保存目标文件的绝对路径,末尾不带“/”,strPath(数据类型:字符串);
---- 返回值:成功,则为保存的目标文件名(数据类型:字符串);
----------- 失败,则返回零长度字符串。
---- 本文升级的ASP组件与原文的ASP组件保持二进制兼容,即保留了原版本的全部接口,并增加了增强的接口,其规范说明如下:
---- 3、 功能:增强型保存上载文件,建议不再使用方法SaveTheFile
---- 方法名:ExSaveTheFile
---- 形参:1、提交表单中文件类型元素名称,strTag(数据类型:字符串);
--------- 2、保存目标文件的绝对路径,末尾不带“/”,strPath(数据类型:字符串);
--------- 3、保存的目标文件名(支持长文件名),strDesFileName(数据类型:字符串);
---- 此参数可选参数,未指定时,以源文件名作为目标文件名;
---- 返回值:成功,则为保存的目标文件名(数据类型:字符串);
----------- 失败,则返回零长度字符串。
---- 在ASP上载文件组件的新版本中,调用方法ExSaveTheFile如忽略可选取参数strDesFilename,则可以实现与方法SaveTheFile相同的功能;选取参数时,目标文件名既可以是用户指定的新文件名,也可以根据用户ID或cookie及数据库中的信息来生成,具有较强的实际应用价值。
---- 值得一提的是,在ActiveX DLL工程属性中应设置版本的二进制兼容并选择一个合适的基地址;另外,VB6提供一个打包和展开向导(Package &amp;
Deployment Wizard)用于将ActiveX部件打包成CAB文件并可部署到远程IIS服务器上。
---- 其次,解决ASP编程中调用ActiveX部件的参数类型匹配问题。由于ASP环境中变量都是Variant类型,直接以之作为ASP上载文件组件的实参就会产生类型不匹配的错误。根据笔者的经验和对ActiveX部件的反复测试,找到了以下解决方法:
---- 如果VarPara是ASP环境中的变量,则“” &amp;
VarPara可以匹配用VB编写的ActiveX部件中string数据类型。
---- 基于客户端的验证只是一个实现策略上的问题,可直接参考下面的例子(新ASP文件上载组件的全限定名改为UpLoad.UploadFile):
---- 示例文件upload.htm 和 示例文件upload.asp,可在此下载。
---- 以上例子在VB 6.0和IIS 4.0下测试通过。
 
S

smilboy

Unregistered / Unconfirmed
GUEST, unregistred user!
你的原代码我没看见呀!还有最好文件的上在可以使用NT的PSHOST.DLL。
请接续!谢谢
 
X

xWolf

Unregistered / Unconfirmed
GUEST, unregistred user!
其实对于ASP我也不是很懂, 上面两篇文章都是在网上看到的.
示例文件upload.htm 和 示例文件upload.asp:
http://www.ccw.com.cn/99/tips/9909/090301_06.zip
 
W

Walone

Unregistered / Unconfirmed
GUEST, unregistred user!
哪里有pshost.dll?
在哪里下上面所说的ASP组件?
 
S

sgh

Unregistered / Unconfirmed
GUEST, unregistred user!
请问xWolf:“ upload.asp所用到的组件,那里可以下载“
 
G

ghj1976

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi4.0 开发WEBMAIL程序
返回
---- 通常,实现WEBMAIL采用mailto.exe的CGI、在HTML文件中写入“< form action="mailto:电子邮箱地址" method=post >”语句或者调用WINDOWS API函数。采用WINDOWS API 和在HTML文件中写入“< form action="mailto:电子邮箱地址" method=post >”语句都要求用户的浏览器装入EXCHANGE、OUTLOOKEXPRESS、或OUTLOOK等软件,而且还有一些浏览器不支持MAILTO语句。而采用CGI的形式实现WEBMAIL对用户的浏览器没有要求,但效率不高。CGI技术正在逐渐被ISAPI/NSAPI技术所取代。本文就来讨论一下采用ISAPI技术实现WEBMAIL。
---- 使用Delphi 4开发Web Server程序是非常简单的,Delphi 4中提供了大量的元件和对象,支持Web Server程序的开发。 下面通过一个例子来介绍如何利用DELPHI开发一个响应用户输入的ISAPI的WEBMAIL程序。只有在发送服务器上注册的用户才能通过在浏览器发送邮件。为了简单,程序没有对传送的数据提供保密。
---- 首先,在WEB服务器端安装数据库引擎dbe,并设置好数据库别名:yh,指向一个包含用户名和用户密码的数据库文件user.db。接着建立两个HTML文件,名字分别为:dl.html,qd.html,放在WEB服务器的缺省目录下(如:C:/INETPUB/WWWROOT)。
dl.html的内容如下:
< html >
< head >< title > 发送邮件系统< /title >< /head >
< body >
< h1 >发送邮件系统< /h1 >
< p > 请输入您的用户名及密码。< /p >
< form method=”post” action="/scripts/xsmd" >
< p >用户名:< input type="text" length=10
name="username" >
密码:< input type="password"
length=10 name="password" >< /p >
< p >< input type="submit" value="确定" >
< input type="reset" value="清除" >< /p >
< /form >
< /body >
< /html >
qd.html文件内容如下:
< html >< head >< title >填表< /title >< /head >
< body >
< form method=”post” action="feedback" >
< p >请填入接收邮件地址:toaddress:
< input type=”text” length=20
name=”toaddress” >< /p >
< p >请填入主题。< input type="text"
length=20 name="subject" >< /p >
< p >内容:< /p >
< p >< input type=“textarea”length=40
width=40 name=”body” >< /p >
< p >< input type="submit" value="确定" >
< input type="reset" value="清除" >< /p >
< /form >
< /body >
< /html >
 
---- 在DELPHI中新建一个基于ISAPI的WEB SERVER APPLICATION,手动增加nmsmtp1,query1,pageproducer1。
---- 其中:pageproducer1的property: htmlfile:c:/inetpub/www.root/qd.html。nmsmtp1的 property:host(发送邮件服务器的地址。)在这里为smtp.netease.com.。port:25。 全局变量为: sername:string;flag:boolean;

增加一个路径为/feedback的动作项,其代码如下:
procedure TWebModule1.WebModule1WebActionItem1
Action(Sender: TObject;
Request: TWebRequest;
Response:
TWebResponse;
var Handled: Boolean);
Var Count:integer;
S:string;
begin
Query1.close;
Query1.sql.clear;
S:=’select count(username) from
user.db where username=”’;
S:=s+request.contentfields.values[‘username’]+’”’;
S:=s+’ and password=”’;
S:=s+request.contentfields.values[‘psword’]+’”’;
Query1.sql.add(S);
Query1.open;
If query1.count=0
then
response.content:=’< html >< head >< title >
< /title >< body >用户名、密码不正确,请重新输入
< /body >< /html >’
else

Username:=request.contentfields.values[‘username’];
Response.content:=pageproducer1.content;
end;

再增加一个路径为/sendmail 的动作项,
它的程序代码如下:
procedure TWebModule1.WebModule1Web
ActionItem2Action(Sender: TObject;
Request: TWebRequest;
Response:
TWebResponse;
var Handled: Boolean);
Var body:string;
begin
Flag:=true;
body:=request.contentfields.values[‘body’];
Pageproducer1.htmldoc.clear;
Pageproducer1.htmldoc.add(‘< html >< body >’);
Nmsmtp1.postmessage.clear;
Nmsmtp1.postmessage.fromaddress:=username+
’@netease.com’;
Nmsmtp1.postmessage.from:=username;
Nmsmtp1.postmessage.body.add(body);
Nmsmtp1.postmessage.toaddress.add
(request.contentfields.values[‘toaddress’]);
Nmsmtp1.postmessage.subject:=
request.contentfields.values[‘subject’];
Nmsmtp1.connect;
If flag=true then
begin
Nmsmtp1.sendmail;
nmsmtp1.disconntent;
end
pageproducer1.htmldoc.add
(‘< /body >< /html >’);
response.content:=pageproducer1.content;

end;

增加nmsmtp1的事件如下:
procedure TWebModule1.NMSMTP1Connect(Sender: TObject);
begin
pageproducer1.htmldoc.add
('< p >已经和发送邮件服务器连接< /p >');
end;

procedure TWebModule1.NMSMTP1Connection
Failed(Sender: TObject);
begin
flag:=false;
pageproducer1.htmldoc.add
('< p >连接失败< /P >');
end;

procedure TWebModule1.NMSMTP1ConnectionRequired
(var Handled: Boolean);
begin
pageproducer1.htmldoc.add('< p >要求进行连接< /p >');
end;

procedure TWebModule1.NMSMTP1Failure(Sender: TObject);
begin
pageproducer1.htmldoc.add('< p >发送邮件失败< /p >');
flag:=false;
end;

procedure TWebModule1.NMSMTP1Header
Incomplete(var handled: Boolean;
hiType: Integer);
begin
pageproducer1.htmldoc.add('< p >head不完整< /p >');
flag:=false;
end;

procedure TWebModule1.NMSMTP1InvalidHost
(var Handled: Boolean);
begin
pageproducer1.htmldoc.add('< p >
发送邮件服务器地址无效< /p >');
flag:=false;
end;

procedure TWebModule1.NMSMTP1RecipientNot
Found(Recipient: String);
begin
pageproducer1.htmldoc.add
('< p >接受邮件地址不正确< /p >');
flag:=false;
end;

procedure TWebModule1.NMSMTP1Success(
Sender: TObject);
begin
pageproducer1.htmldoc.add('< p >
成功发送邮件< /p >');
end;
 
---- 将project存为sendmail.dpr,编译后放到WEB服务器的可执行文件路径下(如:c:/intpub/scripts),即可响应HTML文件dl.htm的用户输入,并且如果用户的用户名及密码正确则可进入发送邮件的页面,用户填写接受邮件地址及主题、内容后即可发送邮件。此程序在NT SERVER上调试通过。
返回
 

编程浪子

Unregistered / Unconfirmed
GUEST, unregistred user!
ADO直接调用WEB
 
S

smilboy

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 

Similar threads

X
回复
0
查看
498
xalion
X
回复
0
查看
794
不得闲
回复
0
查看
841
不得闲
顶部