dopo che ho inviato il post mi è venuto in mente che il codice non funzionava cmq basta connettersi ad un mail server tipo pop.tiscali.it
codice:
Imports System.Net.Sockets
Public Class Form1
Private Function receiveCommand(ByVal cli As TcpClient, _
ByVal strm As NetworkStream) As String
Dim msg As String = Chr(34)
Try
'dichiaro la matrice di byte
Dim byteServer(cli.ReceiveBufferSize + 1) As Byte
'leggo l'array di byte che mi restituisce il server
strm.Read(byteServer, 0, byteServer.Length)
byteServer(byteServer.Length - 1) = 43
'converto i byte in stringa
msg = System.Text.Encoding.ASCII.GetString(byteServer) & msg
' --------------------------------------------
' se qui controlli il valore di msg vedi che mancano le virgolette finali
' --------------------------------------------
Return msg
Catch ex As Exception
Return "EXCEPTION - " & ex.Message
End Try
End Function
Function connetti()
Dim netStrm As NetworkStream
Dim tcpCli As New TcpClient
Dim msg As String = ""
Try
'Provo a connettermi
tcpCli.Connect("pop.tiscali.it", 110)
'passo al socket stream i valori dello stream tcp
netStrm = tcpCli.GetStream()
msg = receiveCommand(tcpCli, netStrm)
'controllo le prime tre lettere del messaggio
'se con +OK l'operazione è stata eseguita con successo
'se con -ERR c'è stato un errore
If msg.StartsWith("+OK") Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(connetti)
End Sub
End Class