Downloading the list of messages
' This function performs recursively through ' all body parts of the e-mail, counting the number ' of the attachments Function GetAttachmentsCount(objBodyPart) Dim objSubPart GetAttachmentsCount = 0 If objBodyPart.IsMultipart Then ' Body part is grouping part, dig into subparts For Each objSubPart In objBodyPart.SubParts GetAttachmentsCount = GetAttachmentsCount + GetAttachmentsCount(objSubPart) Next ElseIf objBodyPart.Disposition = "attachment" Then ' Body part is attachment GetAttachmentsCount = 1 End If End Function Dim objIMAP4, objEnvelopes, objEnvelope Set objIMAP4 = CreateObject("MailBee.IMAP4") ' Unlock IMAP4 object objIMAP4.LicenseKey = "put your license key here" ' Set IMAP4 server name objIMAP4.ServerName = "mail.server.com" ' Set user credentials objIMAP4.UserName = "username" objIMAP4.Password = "password" ' Connect to the server and ' log in email account If objIMAP4.Connect Then ' Select Inbox folder If objIMAP4.SelectMailbox("Inbox") Then ' Download envelopes together with body structures for ' all e-mails in the folder Set objEnvelopes = _ objIMAP4.RetrieveEnvelopesEx(1, objIMAP4.MessageCount, False, True) If Not objIMAP4.IsError Then For Each objEnvelope In objEnvelopes ' Display "Subject:" (taken from envelope) and number of ' attachments (taken from bdoy structure) for every e-mail MsgBox "Subject: " & objEnvelope.Subject & vbCrLf & _ "Number of attachments: " & _ GetAttachmentsCount(objEnvelope.BodyStructure) Next Else ' Display error information MsgBox "Error #" & objIMAP4.ErrCode & ", " & objIMAP4.ErrDesc End If Else ' Display error information MsgBox "Error #" & objIMAP4.ErrCode & ", " & objIMAP4.ErrDesc End If ' Close the connection objIMAP4.Disconnect Else ' Display error information MsgBox "Error #" & objIMAP4.ErrCode MsgBox "Server response: " & objIMAP4.ServerResponse End If
<% ' This function performs recursively through ' all body parts of the e-mail, counting the number ' of the attachments Function GetAttachmentsCount(objBodyPart) Dim objSubPart GetAttachmentsCount = 0 If objBodyPart.IsMultipart Then ' Body part is grouping part, dig into subparts For Each objSubPart In objBodyPart.SubParts GetAttachmentsCount = GetAttachmentsCount + GetAttachmentsCount(objSubPart) Next ElseIf objBodyPart.Disposition = "attachment" Then ' Body part is attachment GetAttachmentsCount = 1 End If End Function Dim objIMAP4, objEnvelopes, objEnvelope Set objIMAP4 = Server.CreateObject("MailBee.IMAP4") ' Unlock IMAP4 object objIMAP4.LicenseKey = "put your license key here" ' Set IMAP4 server name objIMAP4.ServerName = "mail.server.com" ' Set user credentials objIMAP4.UserName = "username" objIMAP4.Password = "password" ' Connect to the server and ' log in email account If objIMAP4.Connect Then ' Select Inbox folder If objIMAP4.SelectMailbox("Inbox") Then ' Download envelopes together with body structures for ' all e-mails in the folder Set objEnvelopes = _ objIMAP4.RetrieveEnvelopesEx(1, objIMAP4.MessageCount, False, True) If Not objIMAP4.IsError Then For Each objEnvelope In objEnvelopes ' Display "Subject:" (taken from envelope) and number of ' attachments (taken from bdoy structure) for every e-mail Response.Write "Subject: " & objEnvelope.Subject & "<br>" & _ "Number of attachments: " & _ GetAttachmentsCount(objEnvelope.BodyStructure) & "<br><br>" Next Else ' Display error information Response.Write "Error #" & objIMAP4.ErrCode & ", " & objIMAP4.ErrDesc End If Else ' Display error information Response.Write "Error #" & objIMAP4.ErrCode & ", " & objIMAP4.ErrDesc End If ' Close the connection objIMAP4.Disconnect Else ' Display error information Response.Write "Error #" & objIMAP4.ErrCode & "<br>" Response.Write "Server response: " & objIMAP4.ServerResponse End If %>See Also: