OnStatusChange Event


Fires when mailbox status is changed: new message arrives, existing message is deleted, number of existing or recent messages changes, etc.

Often, this event is used during idling (see Idle method for details and code example).


Parameters:  
EventCode As Long Type of event:
  • 1 - Expunge. A message was expunged. Message parameter contains the message number
  • 2 - Reserved for future use
  • 3 - Exists. Number of existing messages (MessageCount property) changed. Value parameter contains new number of existing messages
  • 4 - Recent. Number of recent messages (RecentCount property) changed. Value parameter contains new number of recent messages
 
Message As Long Message number. Only valid for Expunge event  
Value as Long Number of messages. Only valid for Exists and Recent events  
ByRef Proceed As Boolean Default value is True, which tells MailBee to continue processing. You can set it to False to immediately abort IMAP4 session and disconnect from IMAP4 server  
Remarks: Events are turned off by default. To enable them, set EnableEvents to True

Usage example:

Option Explicit
' Early binding and "WithEvents" syntax required for handling MailBee's events
Dim WithEvents objIMAP4 As MailBee.IMAP4

Private Sub Command1_Click()
  Dim Envelopes As MailBee.Envelopes
  Set objIMAP4 = CreateObject("MailBee.IMAP4")
  objIMAP4.LicenseKey = "put your license key here"
  objIMAP4.EnableEvents = True ' Enable Async mode
  If objIMAP4.Connect("mailserver.com", 143, "MyName", "MyPassword") Then ' Long-run operation
    If objIMAP4.SelectMailbox("Inbox") Then ' Long-run operation
      Set Envelopes = objIMAP4.RetrieveEnvelopes(1, objIMAP4.MessageCount, False) ' Long-run operation
    End If
    objIMAP4.Disconnect ' Long-run operation
  End If
End Sub

' Respond to MailBee's OnStatusChange event
Private Sub objIMAP4_OnStatusChange(ByVal EventCode As Long, ByVal Message As Long, ByVal Value As Long, Proceed As Boolean)
  Select Case EventCode
  Case 1:
    Debug.Print "Message #" & Message & " was expunged"
  Case 3:
    Debug.Print Value & " messages in mailbox"
  Case 4:
    Debug.Print Value & " recent messages"
  End Select
End Sub Private Sub Form_Load() Set objIMAP4 = Nothing End Sub Private Sub Form_Unload(Cancel As Integer) If objIMAP4 Is Nothing Then Exit Sub If objIMAP4.Busy Then objIMAP4.Abort ' Cancel IMAP4 session on exit End Sub

See Also:

EnableEvents Property

OnAlert Event
OnReceiveData Event


Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.