Handling events

The sample demonstrates retrieving e-mail while staying responsive to user actions. User can abort e-mail downloading process by closing the app.

Note: This sample code is for Visual Basic only. ASP does not support events.

By default, MailBee does not processes Windows events when performing mail operation. This gives maximum performance and fits fine for web applications (such as ASP ones).

Desktop applications, however, usually give user an option to interact with the app even when it is busy (e.g. receives e-mail).

To let MailBee process Windows events, EnableEvents property of POP3 object must be set to True before connecting to POP3 server.

MailBee is also capable of firing its own events (such as download progress). See EnableEvents property documentation for details.

' Declare mailer object global to control
' it within different subroutines
Dim objPOP3

' User clicked the button. Must get e-mail
Private Sub Command1_Click()
  Dim objMsgs

  ' Allow POP3 object to process Windows
  ' events during operation
  objPOP3.EnableEvents = True
  
  ' Unlock POP3 component
  objPOP3.LicenseKey = "put your license key here"
  
  ' Set POP3 server name
  objPOP3.ServerName = "mail.server.com"
  
  ' Set user credentials
  objPOP3.UserName = "username"
  objPOP3.Password = "password"

  ' Connect to the server and log in the mailbox
  If objPOP3.Connect Then

    ' Completely download all messages in
    ' the mailbox (this often takes some time)
    Set objMsgs = objPOP3.RetrieveMessages

    ' Close the connection
    objPOP3.Disconnect
  End If
End Sub

' App launched, create mailer object but
' do not get any e-mail yet
Private Sub Form_Load()
  ' Create mailer component
  Set objPOP3 = CreateObject("MailBee.POP3")
End Sub

' User closed the app
Private Sub Form_Unload(Cancel As Integer)
  ' If e-mail is still being received,
  ' abort mail operation
  If objPOP3.Busy Then objPOP3.Abort
End Sub

See Also:

POP3.EnableEvents Property