dcsimg
December 9, 2016
Hot Topics:

Making a POP3 Client

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »

If you are thinking about deploying email access on the web, then I wouldn't try and just put a VB control on there because it runs very slowly and requires you to download the runtimes and any additional controls onto your machine if they are not already there. I would suggest writing a Perl or Java program or possibly wrapping it into a VB DLL and using ASP to view it. To get a good look at a service that deploys web email, and allows you to download email from other servers, check out BT's Talk21 service: http://www.talk21.com/

So, lets make a connection! First, I will put out the code and after you have had a look through it, I will explain what's going on:

Private Function ConnectToPOP(strServer As String, _
  strUser As String, strPwd As String)As Boolean

Dim strOut As String

ConnectToPOP = False

Winsock1.Connect strServer, 110 
   ' Change the port as necessary
WaitFor 1, strOut

If strOut = "+OK" Then
  Winsock1.SendData "USER " & strUser & vbCrlf
Else
  ConnectToPOP = False
  Exit Function
End If

WaitFor 1, strOut

If strOut = "+OK" Then
  Winsock1.SendData "PASS " & strPwd & vbCrlf
Else
  ConnectToPOP = False
  Exit Function
End If

WaitFor 1, strOut

If strOut = "+OK" Then
  ConnectToPOP = True
Else
  ConnectToPOP = False
End If

End Function

As you can see, the function takes a bit of getting used to. Remember, after each time we send some data, we have to wait for a response. I have wrapped the waiting code into a procedure called WaitFor (you can see this in the sample project). Firstly, we use the Winsock1.Connect method and specifiy the server and the port to connect on. We then wait for a response, and check that the response is +OK, otherwise we bail out. If the response was +OK, then we send the username using the USER command. Again, we wait for a response and if everything is ok, we send the password. If after all this sending, waiting and checking things are still ok, then we are now connected to the server!





Page 5 of 6



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel