利用ASP实现邮箱访问

    您在访问网站时是否会在有些页面上见到这种功能---您在可以访问此网站的同时,还可以查看您免费邮箱中是否有新邮件。这个功能是不是让您觉得很心动、很神秘呢?下面,我就用ASP来举个例子让您知道是如何实现这一功能的。   
     首先你可以去一些提供免费邮件服务的站点,申请一个账号然后登录。在打开邮箱时,请您注意地址栏中的内容。现在以371为例,你会发现其内容通常是:   http://www.371.net/prog/login?user=fighter&pass=mypassword。
    其中"fighter"是您的账号,"mypassword" 是您的密码。这时我们可以从这里得到3个信息。第1条是我们得到了处理文件的url及文件名:"http://www.371 .net/prog/login";第2条是记录您账号的变量名:user;第3条是记录您密码的变量名:pass。我们知道这些信息后,就可着手写html文件和asp文件了。 

'/*Html源文件内容如下:*/    

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<title>City Club 首页</title><br> <style type="text/css">
<!--
td { font-size: 9pt}
body { font-size: 9pt}
select { font-size: 9pt}
A {text-decoration: none; color: #003366; font-size: 9pt}
A:hover {text-decoration: underline; color: #FF0000; font-size: 9pt}
-->
</style>
<script language="javascript">
function check(tt) {
if (window.document.form1.selectmail.selectedIndex==0) {
alert("请选择您的邮箱服务器!")
window.document.form1.selectmail.focus()
return false }
if (tt.account.value=="") {
alert("帐号不能为空!请填写。")
tt.account.focus()
return false }
if (tt.account.value.length<3) {
alert("帐号长度不能小于3位!请填写。")
tt.account.focus()
return false }
if (tt.password.value=="") {
alert("密码不能为空!请填写。")
tt.password.focus()
return false }
if (tt.password.value.length<3) {
alert("密码长度不能小于3位!请填写。")
tt.password.focus()
return false }
else return true
}
</script>
<BODY topmargin=12>
<table border=0 bgcolor=d3d3d3>
<td>
<form action="PostOffice.asp" method=post Onsubmit="return check(this)" name=form1 target="_blank"> <!--此处用target="_blank",是为了弹出新窗口来查看您的邮箱-->
<select style="font-size:9pt;background-color:add8e6" name="selectmail">
<option name="mailsite" value="City Club便民邮局" selected>City Club便民邮局</option>
<option name='MailSite' value='990.net/prog/login?;user;pass;'>990</option>
<option name='MailSite' value='www.371.net/prog/login?;user;pass;'>371</option>
</select><br>
帐号:<input type=text name=account size=12 style="font-size:9pt"><br>
密码:<input type=password name=password size=12 style="font-size:9pt"><br>
</td><tr><td align=center>
<input type=submit value="收信" style="font-size:9pt">
<input type=reset value="重填" style="font-size:9pt">
</td></form>
</td></table>
</BODY>
</HTML>
'/*Html源文件内容结束*/

'/*PostOffice.asp源文件内容如下:*/

<%@ Language=VBScript %>
<%
Response.Buffer = true
'----------------------------------------------------
'Author : Peter.yu
'Created Date : 2000/3/13
'File Name : PostOffice.asp
'All Rights Reserved.所有权归City Club
'----------------------------------------------------
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<title>City Club 便民邮局 (All Rights Reserved所有权归City Club)</title>
<BODY>
<%
dim str(3)
str1 =trim(Request.Form("selectmail")) '/*获取的邮件服务器及用户账号和密码信息*/
for i = 1 to 3 '/*将以上获取的信息进行分割,并赋予给数组变量*/
p = instr(1,str1,";")
str(i-1) = mid(str1,1,p-1)
str1 = mid(str1,p+1)
next
if instr(1,str(0),"http://")=0 then
webSiteUrl = "http://" & str(0)
else
webSiteURL = str(0) '/*邮件服务器地址及指定处理的文件名*/
end if
usernam = str(1) '/*账号变量名*/
password = str(2) '/*密码变更名*/
'/*合并字符,得到诸如"http://www.371.net/prog/login?user=fighter&pass=mypassword的字符"*/ mailUrl = webSiteUrl & usernam & "=" & trim(Request.Form("account"))
mailUrl = mailUrl & chr(38) & password & "=" & trim(Request.Form("password")) Response.Redirect mailUrl '/*打开邮箱*/
%>
</BODY>
</HTML>

'/*PostOffice.asp源文件内容结束*/

    不是很难吧,呵呵。其实这个不是很难的,关键在于您能多多观察,找出其中的规律。这样我们就可以利用这些规律做很多很多有意义有趣的事了。

                              (2000-03-24· 歪歪·CPCW)