22 ottobre 2005 alle 17:36:29 Modificato il 22 ottobre 2005 alle 17:37:52Con questo codice asp.net riesco a connettemi alla casella email ma il response mi dice quanti messaggi ci sono e la loro grandezza ma non mi fa ne leggerli ne inviarli. Dategli un'ochiata
<_Script runat="server">
'E' utile leggere l'RFC 1939 che spiega il Post Office Protocol (POP3) 'ftp://ftp.rfc-editor.org/in-notes/rfc1939.txt
Dim tcpC as New TcpClient()
Sub Page_load() if ispostback() then lblMessaggi.Text = "" ReadMail(host.text, utente.text, pwd.text) end if End Sub
' Manda il comando e restituisce la risposta Function SendCommand(byRef NetStream as NetworkStream, byVal sToSend as String) Dim bData() as Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray) NetStream.Write(bData,0,bData.Length()) Return GetResponse(NetStream) End Function
' Controlla se c'è una risposta e la restituisce Function GetResponse(byRef NetStream as NetworkStream) Dim bytes(tcpC.ReceiveBufferSize) As Byte NetStream.Read(bytes, 0, bytes.length)
'Restituisce i dati ricevuti Dim ReturnData As String = Encoding.ASCII.GetString(bytes) Return ReturnData End Function
Function ReadMail(host as string, user as string, pass as string) Dim NetStream as NetworkStream, MyResponse as string
' apre una connessione con il server di posta sulla porta 110 try tcpC.Connect(host,110) catch MyEx as Exception 'in caso di errore restituisce un messaggio lblMessaggi.Text += "Errore nella connessione all'host: " & host & " (porta 110)<br>" & _ "L'errore riportato è: " & MyEx.message & "<br>Controlla e riprova<br>" end try
' Recupera la risposta try NetStream = tcpC.GetStream() MyResponse = GetResponse(netstream) catch MyEx as Exception lblMessaggi.Text += "Si è verificato un errore!" end try
'Invia il nome dell'utente (account sul server) MyResponse = SendCommand(netstream,"user " & user & vbCrLF)
'Controlla se il collegamento è andato a buon fine if left(MyResponse,4)="-ERR" then lblMessaggi.Text += "Errore nel collegamento dell'utente; controlla i dati e riprova<BR>" lblMessaggi.Text += MyResponse & "<br>" MyResponse=SendCommand(netstream,"QUIT" & vbCrLF) tcpC.close else 'Indica che il collegamento ha avuto successo lblMessaggi.Text += "Utente correttamente collegato<BR><BR>"
'Richiede le statistiche dell'intera casella MyResponse=SendCommand(netstream,"stat" & vbCrLf)
dim tmpArray() as string 'nel primo elemento (indice 0) c'è '+OK' nel secondo il numero dei messaggi, nel terzo la dimensione dei messaggi in bytes tmpArray = split(MyResponse," ")
dim thisMess as integer 'quindi qui trovo il numero dei messaggi dim NumMess as string = tmpArray(1)
if cint(NumMess) > 0 then 'controllo se ci sono messaggi 'Scrivo il numero dei messaggi lblMessaggi.Text += "Ci sono " & NumMess & " messaggi per un totale di " & tmpArray(2) & " bytes<br>" 'per ogni messaggio della casella recupero la dimensione
for thisMess = 1 to cint(numMess) MyResponse = SendCommand(netstream,"list " & thisMess & vbCrLf) tmpArray = split(MyResponse," ")
22 ottobre 2005 alle 17:48:03 Scusami, non vorrei sembrarti sgarbato, ma, forse non ti sei accorto che questo forum tratta di ASP e non ASP.NET, credo tu abbia sbagliato portale, perchè, al momento aspnuke è solo in ASP. Ciauz DJ
--------------- A lavare la testa ai somari, ci si rimette l'acqua e il sapone!