This works fine to suck emails from your POP3 Account and export them as .eml files to C:\Windows\Temp
It's a Winsock solution.
I found it online, have used it and it works just fine. HOWEVER, I am looking for a simple VB6 example (in full) to convert the eml file attachments to files and export them too. So far, I have searched for about 14 hours solid. :-)
I prefer vb6, but would accept a simple vb.net solution. Any help would be appreciated.
Hope this helps.
Converting it from vb6 to vb.net ought to be simple enough.
Cheers,
Kevin
' In general Declarations
Dim received As Boolean
Dim Message$
Dim sckError
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData Message$
Select Case Winsock1.Tag
Case "RETR"
Put #1, , Message$
If InStr(Message$, vbLf + "." + vbCrLf) Then
Close 1
received = True
End If
Case Else
sckError = (Left$(Message$, 3) = "-ER")
received = True
End Select
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub cmdCheckMail_Click()
' LogIn to the server ~ get settings from outlook express
Winsock1.Connect txtHost, 110
Do Until received: DoEvents: Loop
If sckError Then MsgBox "An error occured trying to connect to server": Exit Sub
sendMsg "USER " & txtUsername ' Send UserName
If sckError Then MsgBox "Error with username": Exit Sub
sendMsg "PASS " & txtPass ' Send Password
If sckError Then MsgBox "Error with password": Exit Sub
' Get Number of Messages and total size in bytes
sendMsg "STAT"
x = InStr(Message$, " "): b = InStrRev(Message$, " ")
Messages = Val(Mid$(Message$, x + 1, b - x))
Size = Val(Mid$(Message$, b + 1))
' MsgBox "Number of messages to download " & Messages
' Download all messages
For a = 1 To Messages
' Winsock1_DataArrival will save message as "Email-1.eml", "Email-2.eml" etc
Winsock1.Tag = "RETR"
Open "C:\Windows\Temp\eMail-" & a & ".eml" For Binary Access Write As #1
sendMsg "RETR " & a
List1.AddItem "eMail " & a & ": Downloaded"
Next
Winsock1.Tag = ""
End Sub
Sub sendMsg(m$)
Winsock1.SendData m$ + vbCrLf
received = False
Do Until received
DoEvents
Loop
End Sub