Receiving message headers from POP3 server (Part
2)
Detecting attachments
Summary: Highlights detecting
whether the message has attachments when only message headers are available.
Tutorial map:
Part 1 - Downloading the list
of messages
Part 2 - Detecting attachments
Part 3 - Retrieve a few body lines
along with the headers
When displaying message list to user, it's common to show paper-clip for messages
with attachments.
The POP3 protocol (unlike IMAP4) does not provide a mechanism to preview attachments.
Fortunately, most messages with attachments have some specifics in their headers.
This allows MailBee to detect attachments even if only message headers are available.
Message.HasAttachments
property returns True if the message has one or more attachments.
However, Message.HasAttachments property is not 100% accurate: in rare
cases, message headers do not conform to message contents.
100% reliable way to detect attachments is to download the message completely.
For complete messages, Message.HasAttachments property is 100% accurate.
Sample code description
The sample code prints the information regarding attachments presense for each
message in the mailbox.
Code example:
<% Dim objPOP3, colMsgs, I, strInfo Set objPOP3 = Server.CreateObject("MailBee.POP3") objPOP3.LicenseKey = "put your license key here" ' Connect to POP3 server If objPOP3.Connect("mail.server.com", 110, "user", "pass") Then ' Download headers for all messages Set colMsgs = objPOP3.RetrieveHeaders If objPOP3.IsError Then ' Handle errors Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc Else For I = 1 To objPOP3.MessageCount ' Add message number to string strInfo = "Message #" & I ' Detect attachment presence and ' add the results to string If colMsgs(I).HasAttachments Then strInfo = strInfo & " has attachment(s)" Else strInfo = strInfo & " has no attachment(s)" End If ' Print the string with the results Response.Write strInfo & "<br>" Next End If objPOP3.Disconnect Else ' Handle errors Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc End If %>
See Also:
Part
3 (Retrieve a few body lines along with the headers)
RetrieveHeaders Method
Message.HasAttachments Property
Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.