pop3.aspx by Chris Garrett
1<%@page%>
2<HTML><HEAD><title>Pop3 mail check</title></HEAD>
3<body bgcolor=white>
4
5<%
6
7if isPostback then
8 readMail(host.text,user.text,pass.text)
9else
10
11%>
12
13<form id=calc method=post runat="server">
14
15<P>
16Host <asp:TextBox id=host runat="server"></asp:TextBox>
17<P>
18User <asp:TextBox id=user runat="server"></asp:TextBox>
19<P>
20Pass <asp:TextBox TextMode=Password id=pass runat="server"></asp:TextBox>
21
22
23
24<P>
25<asp:Button id=Button1 runat="server" Text="Login"></asp:Button>
26
27
28
29</FORM>
30
31<%
32
33end if
34
35%>
36
37</body></HTML>
38
39<script language="vb" runat="server">
40 dim tcpC as New system.net.sockets.TcpClient()
41
42 ' send command strings and return the response
43 Function SendCommand(byRef netstream as System.Net.Sockets.NetworkStream,byVal sToSend as String)
44
45 dim bData() as Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)
46 netstream.Write(bData,0,bData.Length())
47 Return GetResponse(netstream)
48 End Function
49
50 ' check if there is a response to get and return it
51 Function GetResponse(byRef netstream as System.Net.Sockets.NetworkStream)
52
53 dim bytes(tcpC.ReceiveBufferSize) As Byte
54 dim ret as integer = netStream.Read(bytes, 0, bytes.length)
55
56
57
58 ' Returns the data received
59 dim returndata As String = Encoding.ASCII.GetString(bytes)
60 return returndata
61
62
63
64 End Function
65
66
67
68 Function ReadMail(host as string, user as string, pass as string)
69
70 ' initialise objects
71 dim netstream as System.Net.Sockets.NetworkStream
72
73 dim thisResponse as string
74
75 ' open connection to server
76 try
77 tcpC.Connect(host,110)
78 catch ex as exception
79 response.write("Error connecting to host: " & ex.message & " - Please check your details and try again")
80 response.end
81 end try
82
83 ' get response
84 netstream = tcpC.GetStream()
85 thisResponse=GetResponse(netstream)
86
87
88 ' enter user name
89 thisResponse=SendCommand(netstream,"user " & user & vbCrLF)
90
91 ' enter password
92 thisResponse=SendCommand(netstream,"pass " & pass & vbCrLf)
93
94 ' check if logged in ok
95 if not left(thisResponse,4)="-ERR" then
96 response.write("<font face=courier>Logged in OK <BR>")
97 else
98 response.write("Error logging in, check your user details and try again<BR>")
99 response.write("<P>" & thisresponse)
100 response.end
101 end if
102
103thisResponse=SendCommand(netstream,"stat" & vbCrLf)
104
105
106dim tmpArray() as string
107tmpArray = split(thisResponse," ")
108
109
110
111dim thisMess as integer
112dim numMess as string = tmpArray(1)
113
114response.write("<p><hr>")
115
116thisResponse = ""
117
118if cint(numMess) > 0 then
119 response.write("Messages: " & numMess & "<br>")
120 for thisMess = 1 to cint(numMess)
121
122
123 thisResponse += replace(SendCommand(netstream,"top " & thisMess & " 10" & vbCrLf),vbcrlf,"<br>")
124
125 next
126else
127 response.write("Messages: None" & "<br>")
128end if
129
130
131
132
133thisResponse += replace(SendCommand(netstream,"stat" & vbCrLf),vbcrlf,"<br>")
134
135tmpArray = split(thisResponse,"+OK")
136
137
138response.write(thisresponse)
139
140dim msg as integer
141for msg = 1 to tmpArray.length-1
142
143 response.write("<h3>#" & msg & "</h1>" & tmpArray(msg) & "<p>")
144
145next
146
147
148
149' close connection
150thisResponse=SendCommand(netstream,"QUIT" & vbCrLF)
151tcpC.close
152
153
154
155 End Function
156
157</script>