<%@page%>
<HTML><HEAD><title>Pop3 mail check</title></HEAD>
<body bgcolor=white>
<%
if isPostback then
readMail(host.text,user.text,pass.text)
else
%>
<form id=calc method=post runat="server">
<P>
Host <asp:TextBox id=host runat="server"></asp:TextBox>
<P>
User <asp:TextBox id=user runat="server"></asp:TextBox>
<P>
Pass <asp:TextBox TextMode=Password id=pass runat="server"></asp:TextBox>
<P>
<asp:Button id=Button1 runat="server" Text="Login"></asp:Button>
</FORM>
<%
end if
%>
</body></HTML>
<script language="vb" runat="server">
dim tcpC as New system.net.sockets.TcpClient()
' send command strings and return the response
Function SendCommand(byRef netstream as System.Net.Sockets.NetworkStream,byVal ToSend as String)
dim bData() as Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)
netstream.Write(bData,0,bData.Length())
Return GetResponse(netstream)
End Function
' check if there is a response to get and return it
Function GetResponse(byRef netstream as System.Net.Sockets.NetworkStream)
dim bytes(tcpC.ReceiveBufferSize) As Byte
dim ret as integer = netStream.Read(bytes, 0, bytes.length)
' Returns the data received
dim returndata As String = Encoding.ASCII.GetString(bytes)
return returndata
End Function
Function ReadMail(host as string, user as string, pass as string)
' initialise objects
dim netstream as System.Net.Sockets.NetworkStream
dim thisResponse as string
' open connection to server
try
tcpC.Connect(host,110)
catch ex as exception
response.write("Error connecting to host: " & ex.message & " - Please check your details and try again")
response.end
end try
' get response
netstream = tcpC.GetStream()
thisResponse=GetResponse(netstream)
' enter user name
thisResponse=SendCommand(netstream,"user " & user & vbCrLF)
' enter password
thisResponse=SendCommand(netstream,"pass " & pass & vbCrLf)
' check if logged in ok
if not left(thisResponse,4)="-ERR" then
response.write("<font face=courier>Logged in OK <BR>")
else
response.write("Error logging in, check your user details and try again<BR>")
response.write("<P>" & thisresponse)
response.end
end if
thisResponse=SendCommand(netstream,"stat" & vbCrLf)
dim tmpArray() as string
tmpArray = split(thisResponse," ")
dim thisMess as integer
dim numMess as string = tmpArray(1)
response.write("<p><hr>")
thisResponse = ""
if cint(numMess) > 0 then
response.write("Messages: " & numMess & "<br>")
for thisMess = 1 to cint(numMess)
thisResponse += replace(SendCommand(netstream,"top " & thisMess & " 10" & vbCrLf),vbcrlf,"<br>")
next
else
response.write("Messages: None" & "<br>")
end if
thisResponse += replace(SendCommand(netstream,"stat" & vbCrLf),vbcrlf,"<br>")
tmpArray = split(thisResponse,"+OK")
response.write(thisresponse)
dim msg as integer
for msg = 1 to tmpArray.length-1
response.write("<h3>#" & msg & "</h1>" & tmpArray(msg) & "<p>")
next
' close connection
thisResponse=SendCommand(netstream,"QUIT" & vbCrLF)
tcpC.close
End Function
</script>
<HTML><HEAD><title>Pop3 mail check</title></HEAD>
<body bgcolor=white>
<%
if isPostback then
readMail(host.text,user.text,pass.text)
else
%>
<form id=calc method=post runat="server">
<P>
Host <asp:TextBox id=host runat="server"></asp:TextBox>
<P>
User <asp:TextBox id=user runat="server"></asp:TextBox>
<P>
Pass <asp:TextBox TextMode=Password id=pass runat="server"></asp:TextBox>
<P>
<asp:Button id=Button1 runat="server" Text="Login"></asp:Button>
</FORM>
<%
end if
%>
</body></HTML>
<script language="vb" runat="server">
dim tcpC as New system.net.sockets.TcpClient()
' send command strings and return the response
Function SendCommand(byRef netstream as System.Net.Sockets.NetworkStream,byVal ToSend as String)
dim bData() as Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)
netstream.Write(bData,0,bData.Length())
Return GetResponse(netstream)
End Function
' check if there is a response to get and return it
Function GetResponse(byRef netstream as System.Net.Sockets.NetworkStream)
dim bytes(tcpC.ReceiveBufferSize) As Byte
dim ret as integer = netStream.Read(bytes, 0, bytes.length)
' Returns the data received
dim returndata As String = Encoding.ASCII.GetString(bytes)
return returndata
End Function
Function ReadMail(host as string, user as string, pass as string)
' initialise objects
dim netstream as System.Net.Sockets.NetworkStream
dim thisResponse as string
' open connection to server
try
tcpC.Connect(host,110)
catch ex as exception
response.write("Error connecting to host: " & ex.message & " - Please check your details and try again")
response.end
end try
' get response
netstream = tcpC.GetStream()
thisResponse=GetResponse(netstream)
' enter user name
thisResponse=SendCommand(netstream,"user " & user & vbCrLF)
' enter password
thisResponse=SendCommand(netstream,"pass " & pass & vbCrLf)
' check if logged in ok
if not left(thisResponse,4)="-ERR" then
response.write("<font face=courier>Logged in OK <BR>")
else
response.write("Error logging in, check your user details and try again<BR>")
response.write("<P>" & thisresponse)
response.end
end if
thisResponse=SendCommand(netstream,"stat" & vbCrLf)
dim tmpArray() as string
tmpArray = split(thisResponse," ")
dim thisMess as integer
dim numMess as string = tmpArray(1)
response.write("<p><hr>")
thisResponse = ""
if cint(numMess) > 0 then
response.write("Messages: " & numMess & "<br>")
for thisMess = 1 to cint(numMess)
thisResponse += replace(SendCommand(netstream,"top " & thisMess & " 10" & vbCrLf),vbcrlf,"<br>")
next
else
response.write("Messages: None" & "<br>")
end if
thisResponse += replace(SendCommand(netstream,"stat" & vbCrLf),vbcrlf,"<br>")
tmpArray = split(thisResponse,"+OK")
response.write(thisresponse)
dim msg as integer
for msg = 1 to tmpArray.length-1
response.write("<h3>#" & msg & "</h1>" & tmpArray(msg) & "<p>")
next
' close connection
thisResponse=SendCommand(netstream,"QUIT" & vbCrLF)
tcpC.close
End Function
</script>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货