E Mails abrufen

Hallo,

ich versuche über GMX ( POP3) meine Mails abzurufen. Soweit klappt es auch. Also wenn Sie nur Text enthalten. Aber sobald da noch ein Anhang mit dran haengt, klappt es nicht mehr, da dann diese Mails nicht mit +OK beginnen, sondern mit Zahlen alla

37 850 15436 534 etc.

Weiss jemand wie ich am besten meine Emails abfrage und die Anhaenge auch abspeichern kann? Desweiteren kann ich mittels den Command „LIST“ meine ganzen Mails abfragen. Aber wie bekomme ich raus ob die schon gelesen wurden und wie der Betreff ist!

Ich kann ja nicht zum Start pauschal mal eben 1800 Mails komplett einlesen :frowning:

Mein bisheriger Source ( Die Klasse auf die ich zugreife) ist folgender

Imports System.Net

Public Class ReceiveMail

#Region "Private Variablen"

 Private Connected As Boolean = False
 Private Client As New Sockets.TcpClient
 Private POP3Stream As Sockets.NetworkStream
 Private CancelConnection As Boolean = True

#End Region

#Region "Eigenschaften"

 Public ReadOnly Property ConnectionEstablished As Boolean
 Get
 Return Connected
 End Get
 End Property

#End Region

#Region "Events"

#End Region

#Region "Methoden"

 Sub New(ByVal OnErrorCancelConnection As Boolean)
 Me.CancelConnection = OnErrorCancelConnection
 End Sub

 Public Sub Connect(ByVal Server As String, ByVal User As String, ByVal Password As String)
 If Me.Connected Then Me.DisConnect()
 Try
 Me.Client.Connect(Server, 110)
 Me.POP3Stream = Client.GetStream
 Me.CheckResponse(Me.GetResponse)
 Me.Send(Commands.User + User)
 Me.CheckResponse(Me.GetResponse)
 Me.Send(Commands.Password + Password)
 Me.CheckResponse(Me.GetResponse)
 Me.Connected = True
 Catch ex As Exception
 Me.DisConnect()
 Throw New ApplicationException(ex.Message, ex)
 End Try
 End Sub

 Public Sub DisConnect()
 If Me.Connected Then
 Me.Send(Commands.Quit)
 Me.CheckResponse(Me.GetResponse)
 Me.Connected = False
 Me.Client.Close()
 End If
 End Sub

 Public Sub CheckResponse(ByVal Response As String)
 If Not String.Compare(Response.Substring(0, 3), Commands.ServerConfirm, False, Globalization.CultureInfo.CurrentCulture) = 0 Then
 If Me.CancelConnection Then
 Me.Client.Close()
 Me.Connected = False
 End If
 Throw New ApplicationException("Response " + Response + " not expected.")
 End If
 End Sub

 Private Function GetResponse() As String
 Dim SR As New IO.StreamReader(Me.POP3Stream)
 Dim sBuilder As New Text.StringBuilder
 While SR.Peek \> -1
 sBuilder.Append(SR.ReadLine + vbCr)
 End While
 Return sBuilder.ToString
 End Function

 Public Sub Send(ByVal Command As String)
 Dim Data As Byte() = Text.Encoding.ASCII.GetBytes(Command & vbCrLf)
 Me.POP3Stream.Write(Data, 0, Data.Length)
 End Sub

 Public Function GetMessageList() As List(Of MessageList)
 Dim Pop31 As New List(Of MessageList)
 If Not Me.Connected Then
 Throw New InvalidOperationException("Not Connected!")
 Else
 Me.Send(Commands.List)
 Dim Response As String() = Me.GetResponse.Split(vbCrLf)
 'Abfrage ob Response 0 existiert
 Me.CheckResponse(Response(0))
 For I As Integer = 1 To Response.Length - 3
 Dim POP3m As New MessageList
 POP3m.ID = I
 POP3m.Size = Convert.ToInt64(Response(I).Split(" ")(1))
 Pop31.Add(POP3m)
 POP3m = Nothing
 Next
 End If
 Return Pop31
 End Function

 Public Function GetMessage(ByVal MessageID As Int64) As String
 If Not Me.Connected Then
 Throw New InvalidOperationException("Not Connected!")
 Else
 Me.Send(Commands.GetMessage & MessageID)
 Me.CheckResponse(Me.GetResponse) 'Hier tritt ein Fehler auf wenn die Mail nicht mit +OK beginnt
 Return Me.GetResponse
 End If
 End Function

#End Region

End Class

Public Class MessageList

 Public ID As Int64
 Public Size As Int64

End Class

Public Class Commands

 Public Const Delete As String = "DELE "
 Public Const GetMessage As String = "RETR "
 Public Const List As String = "LIST"
 Public Const Password As String = "PASS "
 Public Const Quit As String = "QUIT"
 Public Const ServerConfirm As String = "+OK"
 Public Const ServerNoMoreData As String = "."
 Public Const User As String = "USER "
 Public Const ServerError As String = "-ERR"
 Public Const NumberofMails As String = "STAT "

End Class

MfG Alex

Hallo!
Schau mal: http://www.codeproject.com/search.aspx?q=pop3&x=0&y=…
Da gibt es jede Menge Implementierungen von POP3 Clients.
Wenn Du die Funktionalität nur nutzen willst, ohne das Rad zum x-ten Mal neu zu erfinden, kannst Du Dich da bedienen.
Wenn Du lernen willst, wie es geht, lies’ Dir den dortigen Quellcode und die Artikel durch.

Gruß,
Martin