您可能感兴趣的话题:
Delphi
核心提示:WebMail是指在网页中实现邮件的发送。使用Delphi开发Web Server程序是非常简单的,Delphi中提供了大量的元件和对象。
WebMail是指在网页中实现邮件的发送。使用Delphi开发Web Server程序是非常简单的,Delphi中提供了大量的元件和对象。下面通过一个例子来介绍如何利用Delphi开发一个响应用户输入的ISAPI的WebMail程序。为了简单,程序没有对传送的数据提供保密。
首先,在Web服务器端安装数据库引擎dbe,并设置好数据库别名:yh,指向一个包含用户名和用户密码的数据库文件user.db。接着建立两个HTML文件,名字分别为:dl.html,qd.html,放在Web服务器的缺省目录下(如:c:\inetpub\wwwroot)。
dl.html的内容如下:
发送邮件系统发送邮件系统
请输入您的用户名及密码
用户名
密码:< input type="password" length=10 name="password" >
qd.html文件内容如下:
填表请填入接收邮件地址:toaddress:
请填入主题
内容:
=40 name=”body”>
在Delphi中新建一个基于ISAPI的Web Server Application,手动增加nmsmtp1,query1,pageproducer1。其中:pageproducer1的htmlfile属性为c:\inetpub\www.root\qd.html。nmsmtp1的host(发送邮件服务器的地址)在这里为smtp.netease.com.,port:25。全局变量为:sername:string;flag:boolean。
增加一个路径为feedback的动作项,其代码如下:
Var
Count:integer;
S:string;
Begin
Query1.close;
Query1.sql.clear;
S:=’select count(username) from user.dbswheresusername=”’;
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:=
’
’
Else
Username:=request.contentfields.values[‘username’];
Response.content:=pageproducer1.content;
End;
再增加一个路径为Sendmail的动作项,它的程序代码如下:
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(‘