2011-09-07 85 views
0
Winsock1.Connect "mail.website.com", 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)) 
If messages = "0" Then 
MsgBox "no new messages" 
GoTo l 
End If 

For a = 1 To messages 
    Winsock1.Tag = "RETR" 
    Open "C:\Windows\Temp\eMail-" & a & ".eml" For Binary Access Write As #1 

    sendMsg "RETR " & a 
    List1.AddItem "eMail-" & a & ".eml" 
    Next 

    Winsock1.Tag = "" 

Next 
l: 
Winsock.Close 

当我运行这个它第一次完美的作品,但是当我尝试运行它第二次W/O关闭应用程序,它给了我40009错误。我想在即将连接之前发送数据。有没有办法查看winsock是否连接?财产以后像Winsock错误40009 VB6

如果winsock1.state = true,那么...

回答

0

你没有列出所有的代码,但我猜测该变量received没有被复位,致使您摔倒通过直接代码早于sendMsg "USER username"。在开始写入套接字之前,必须让连接实际发生/完成。

+0

我该如何去做,有没有像 – gary

+0

如果你可以发布更多的代码,协助会更容易。但一般情况下,您需要等到连接完成后才能进行I/O操作。发生这种情况时有一个Connect事件通知您。 – tcarvin