Priklad funkce pro pripojeni na postovni server pres POP3. Timto zpusobem muzete komunikovat s mail serverem. Staci dopsat dalsi funkce pro POP3 prikazi LIST TOP RETR STATS QUIT atd.
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'vpripade uspesneho prihlaseni +OK
respone.write(ConnectToServer("192.168.3.104"),110,"muj_username","moje_heslo")
End Sub
Public command As String
Public bData As Byte()
Public ch_TcpClient As TcpClient
Public ch_NetStream As NetworkStream
Public ch_ReadStream As StreamReader
Public Function ConnectToServer(ByVal pop3host As String, ByVal port As Integer, ByVal user As String, ByVal pwd As String) As String
' vytvoreni POP3 pripojeni
ch_TcpClient = New TcpClient(pop3host, port)
Try
' incializace
ch_NetStream = ch_TcpClient.GetStream()
ch_ReadStream = New StreamReader(ch_TcpClient.GetStream())
ch_ReadStream.ReadLine()
' odeslani prihlasovaciho jmena
command = "USER " & user & "" & Chr(13) & "" & Chr(10) & ""
bData = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray())
ch_NetStream.Write(bData, 0, bData.Length)
ch_ReadStream.ReadLine()
' odelsani hesla
command = "PASS " & pwd & "" & Chr(13) & "" & Chr(10) & ""
bData = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray())
ch_NetStream.Write(bData, 0, bData.Length)
ch_ReadStream.ReadLine()
Catch err As InvalidOperationException
Return ("Error: " + err.ToString())
End Try
Return "+OK"
End Function
|