Search Method


On success, retrieves UIDs (unique IDs) of all messages in currently opened mailbox. These IDs are returned as an array of strings. Lower bound of the array is 1 and upper bound is MessageCount.

On failure, returns Empty. In Visual Basic or ASP, you can use IsEmpty(Expression) function to handle this situation. Use ErrCode or ErrDesc properties to get detailed error description.

Don't confuse UID with MessageID. UID is a string which is unique for each message in the mailbox. MessageID is a message header (not a number) unique for each distinct message. However, if the same message is placed into mailbox twice, both copies will have the same MessageIDs but different UIDs.

UIDs are very useful for locating new messages because UIDs are retrieved MUCH FASTER then MessageIDs. For example, if you have database table where UIDs of existing messages are stored, it becomes very simple to determine that new messages have arrived. Just call Search method and then search returned values in the UIDs database table. If particular UID is not there, the message is new.

Often (but this depends on mail server implementation), UIDs returned by this method are the same UIDs that returned by Search method of IMAP4 object for "Inbox" folder. However, POP3 UIDs are returned as strings (which may or may not to be presented as numbers) while IMAP4 UIDs are always numbers.

Note: UID functionality is an extension to POP3 protocol, and implementations may vary from server to server (some servers might not support UID at all).


arrUIDs = ObjectName.Search  
Parameters: None 
Return value As Variant Array (1 to MessageCount) of Variant/String, each value is UID of the message. If error has occurred (connection error or UID functionality is not supported), return value is Empty  

Usage example:

Dim Mailer, UIDs, I
'Using visual basic to create object
Set Mailer = CreateObject("MailBee.POP3")
'Using ASP to create object
'Set Mailer = Server.CreateObject("MailBee.POP3")
'In ASP use Response.Write instead of MsgBox
Mailer.LicenseKey = "put your license key here"
If Mailer.Connect("mailserver.com", 110, "MyName", "MyPassword") Then
  UIDs = Mailer.Search ' Get UIDs
  If Not IsEmpty(UIDs) Then
    For I = LBound(UIDs) To UBound(UIDs)
      MsgBox "Message #" & I & " has UID: " & UIDs(I)
    Next
  End If
  Mailer.Disconnect
End If

See Also:

RetrieveHeaders Method
MessageCount Property

Message.MessageId Property

IMAP4.Search Method


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