Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving EMail Attachments

Status
Not open for further replies.

DSTR3

Technical User
Joined
Jan 21, 2005
Messages
41
Location
US
I'm using the following code to download EMails with VB6, but I can't figure out how to save an attachment. Any help appreciated.
Thanks
DS

' 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 "pop.freeserve.net", 110

Do Until received: DoEvents: Loop

if sckError then msgbox "An error occured trying to connect to server" : Exit sub

sendMsg "USER username" ' Send UserName
if sckError then Msgbox "Error with username" : Exit sub

sendMsg "PASS password" ' 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
 
Looks like you've decided to attack this problem after all... but with stone knives and bearskins (i.e. Winsock). Great though, and good luck.

You may want to look at some references. Probably start with: How to send email attachments using Perl / MIME::Lite. The Perl stuff will mostly be irrelevant to you, but there is a gentle intro to MIME encoding of multipart email messages there. It should help you make more sense of the canonical references.

See: Multipurpose Internet Mail Extensions MIME for links to most of the most relevant RFCs.
 
Thanks for your reply, I have some examples of how to do this, so I'm going to dig in even further and try, maybe I need a bigger stone or stick since I barely can figure out what I'm doing! Once again, Thank you!
DSTR3
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top