当前位置:首页 > 网络编程 > 软件语言 > DELPHI > 用Delphi开发简单的WebMail程序

用Delphi开发简单的WebMail程序

点击次数:54 次 发布日期:2008-11-09 08:41:35 作者:源代码网
源代码网推荐
广告载入中
文/北京 张维
源代码网推荐
源代码网推荐   WebMail是指在网页中实现邮件的发送。使用Delphi开发Web Server程序是非常简单的,Delphi中提供了大量的元件和对象。下面通过一个例子来介绍如何利用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/SendMail">
源代码网推荐
源代码网推荐   <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的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:=
源代码网推荐
源代码网推荐   ’<html><head><title>
源代码网推荐
源代码网推荐   </title>
源代码网推荐
源代码网推荐   <body>用户名、密码不正确,请重新输入</body>


源代码网推荐
源代码网推荐   </html>’
源代码网推荐
源代码网推荐   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(‘</body></html>’);
源代码网推荐
源代码网推荐   response.content:=pageproducer1.content;
源代码网推荐
源代码网推荐   end;
源代码网推荐
源代码网推荐   增加nmsmtp1的OnConnect事件添加如下代码:
源代码网推荐
源代码网推荐   pageproducer1.htmldoc.add("<p>已经和发送邮件服务器连接</p>");
源代码网推荐
源代码网推荐   在NMSMTP1的Connection事件添加如下代码:
源代码网推荐
源代码网推荐   flag:=false;
源代码网推荐
源代码网推荐   pageproducer1.htmldoc.add("<p>连接失败</P>");
源代码网推荐
源代码网推荐   将project存为sendmail.dpr,编译后放到Web服务器的可执行文件路径下(如:c:\intpub\scripts),即可响应HTML文件dl.htm的用户输入,并且如果用户的用户名及密码正确,则可进入发送邮件的页面。用户填写接受邮件地址及主题、内容后,即可发送邮件。此程序在NT Server上调试通过。


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华