ANPOP Developers Center > Using ANPOP in Visual Basic.NET

You should download the anpop installer and install it on your machine at first. If you want to distribute or deploy anpop without anpop installer, please click here to learn more.

Add Reference of ANPOP in your project

First of all, make sure ANPOP has been installed on your machine. Then create a Windows Form project in Visual Studio.NET:  select menu "Project" -> "Add Reference" -> COM, and select "ANPOP POP3 COMPONENT BUILD".

Declare and define objects

Imports ANPOPLib;
....
private m_oPop3 As New POPMAINClass();
private m_oMsg  As New POPMSGClass();	
private m_oStore As New MSGSTOREClass();

Although you can create new object instance each time, we recommend to declare object as member variable so that you just need to create it once and then enjoy  reuse those member variables without re-create it again.

How to retrieve and parse email

The following code demonstrates how to retrieve and parse email

Sub Retrieve( pop3Server As String, pop3User As String, pop3Password As String )
  Dim oPop3 As POPMAINClass
  Dim oMsg As POPMSGClass
  Dim i, nRet, nSize, nCount As Integer
  Dim emailContent, messageId As String
  Dim emailSubject, emailBody As String
  
  Try
  
  oPop3 = new POPMAINClass() 'Create object instance
  oMsg  = new POPMSGClass()
  
  nRet = oPop3.Connect( pop3Server, pop3User, pop3Password ) 'Connect pop3 server
  If nRet <> 0 Then
    Throw New Exception( "error with connecting server" )
  End If
  
  nCount = oPop3.GetTotalOfMails() 'Get total count of emails
  If nCount = -1 Then
    Throw New Exception( "error with GetTotalOfMails" )
  ElseIf nCount = 0 Then
    Throw New Exception( "no email" )
  End If
  
  For i = 1 To nCount
    nSize = oPop3.GetMsgSize(i) 'Get email size
    If nSize = -1 Then
      Throw New Exception( "error with GetMsgSize" ) 
    End If
    
    messageId = oPop3.GetMsgID(i) 'Get message-id
    If messageId = vbnullstring Then
      Throw New Exception( "error with GetMsgId" ) 
    End If
    
    emailContent = oPop3.Retrieve(i) 'Retrieve email
    If emailContent = vbnullstring Then
      Throw New Exception( "error with Retrieve" )
    End If
    
    oMsg.RawContent = emailContent
    emailSubject = oMsg.GetSubject() 'parse email subject
    emailBody = oMsg.GetBodyText() 'parse email body
    nRet = oMsg.ExportFile( "c:\pop3Test_" & i & ".eml") 'Save email
    If nRet <> 0 Then
      Throw New Exception( "error with ExportFile" )
    End If
    
    If oPop3.Delete(i) <> 0 Then 'Delete email from server
      Throw New Exception( "error with Delete" )
    End If
  Next
  
  Catch e As Exception
    MsgBox( e.Message )
    
  End Try
  
  oPop3.Close() 'Close connection
  oPop3 = Nothing
  oMsg = Nothing
End Sub

Asynchronous mode and event driving

If you want to use POPMAIN in asynchronous mode, you MUST declare it as a member variable in your project with "WithEvents" key word.

Imports ANPOPLib
...
Private WithEvents m_oPop3 As New POPMAINClass()
Private m_oMsg As New POPMSGClass()
Private m_oStore As New MSGSTOREClass()

Note*: You SHOULD NOT invoke Connect method any more while POPMAIN is connecting with pop3 server, otherwise this connection would be terminated automatically.

A Total Sample

Please refer to POP3QUEUE in ANPOP installation package.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2008 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map