Search for new messages
' This is main function. It retrieves new messages from ' the POP3 server and shows "Subject:" field of each ' retrieved message. Sub RetrieveNewMessages() Dim objPOP3, objMsg, I ' Array of Unique-IDs (taken from the POP3 server) Dim arrIDs ' Create POP3 object Set objPOP3 = CreateObject("MailBee.POP3") ' Unlock POP3 object 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 ' Get Unique-IDs for all messages in the mailbox arrIDs = objPOP3.Search ' Iterate through all messages in the mailbox For I = 1 To objPOP3.MessageCount ' Search Unique-ID of the message in the database If IsNewMessage(arrIDs(I)) Then ' Download new message entirely Set objMsg = objPOP3.RetrieveSingleMessage(I) ' Display the message's Subject MsgBox objMsg.Subject End If Next ' Close the connection objPOP3.Disconnect Else ' Display error information MsgBox "Error #" & objPOP3.ErrCode MsgBox "Server response: " & objPOP3.ServerResponse End If End Sub ' This helper function should lookup the ID in the ' database, and then return True if the ID does not ' exist in the list of already downloaded messages. Function IsNewMessage(ID) ' For demo purposes, the function always returns True. IsNewMessage = True End Function
' This is main function. It retrieves new messages from ' the POP3 server and shows "Subject:" field of each ' retrieved message. Sub RetrieveNewMessages() Dim objPOP3, objMsg, I ' Array of Unique-IDs (taken from the POP3 server) Dim arrIDs As Variant ' Create POP3 object Set objPOP3 = Server.CreateObject("MailBee.POP3") ' Unlock POP3 object 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 ' Get Unique-IDs for all messages in the mailbox arrIDs = objPOP3.Search ' Iterate through all messages in the mailbox For I = 1 To objPOP3.MessageCount ' Search Unique-ID of the message in the database If IsNewMessage(arrIDs(I)) Then ' Download entire message Set objMsg = objPOP3.RetrieveSingleMessage(I) ' Display the message's Subject Response.Write objMsg.Subject & "<br>" End If Next ' Close the connection objPOP3.Disconnect Else ' Display error information Response.Write "Error #" & objPOP3.ErrCode & "<br>" Response.Write "Server response: " & objPOP3.ServerResponse End If End Sub ' This helper function should lookup the ID in the ' database, and then return True if the ID does not ' exist in the list of already downloaded messages. Function IsNewMessage(ID) ' For demo purposes, the function always returns True. IsNewMessage = True End FunctionSee Also: