Detecting attachments

The sample detects whether any attachments are present for each message in the mailbox.

To get attachments status, only message headers are retrieved.

HasAttachments property of Message object is a key property of this sample.

Note: Seldom, message headers say that attachments are present but there are really no any attachments. Download of entire message (not just headers) makes HasAttachments property to be 100%-accurate.

Visual Basic

Dim objPOP3, objMsg, objMsgs, I

' 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

  ' Download headers for all messages
  Set objMsgs = objPOP3.RetrieveHeaders

  If Not objPOP3.IsError Then
	' Display notification for messages with attachments
	For I = 1 To objMsgs.Count
	  If objMsgs(I).HasAttachments Then
		MsgBox "Message #" & I & " has attachments"
	  End If
	Next
  Else
	' Display error information
	MsgBox "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
  End If

  ' Close the connection
  objPOP3.Disconnect
Else
  ' Display error information
  MsgBox "Error #" & objPOP3.ErrCode
  MsgBox "Server response: " & objPOP3.ServerResponse
End If

ASP

<%
Dim objPOP3, objMsg, objMsgs

' 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

  ' Download headers for all messages
  Set objMsgs = objPOP3.RetrieveHeaders

  If Not objPOP3.IsError Then
	' Display notification for messages with attachments
	For I = 1 To objMsgs.Count
	  If objMsgs(I).HasAttachments Then
		Response.Write "Message #" & I & " has attachments<br>"
	  End If
	Next
  Else
	' Display error information
   Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
  End If

  ' Close the connection
  objPOP3.Disconnect
Else
  ' Display error information
  Response.Write "Error #" & objPOP3.ErrCode & "<br>"
  Response.Write "Server response: " & objPOP3.ServerResponse
End If
%>

See Also:

Message.HasAttachments Property