![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) Read IMAP Email HeadersThis example demonstrates how to connect to an IMAP server and download only the email headers for all messages in a mailbox. Downloading headers only is much faster and more efficient than downloading complete emails because the message bodies and attachment contents are not retrieved. The example shows how to:
This technique is useful for quickly scanning large mailboxes, building message summaries, or inspecting attachment information while minimizing bandwidth and memory usage. Note: This example requires Chilkat v11.0.0 or greater.
llSuccess = .F. llSuccess = .F. // This example assumes the Chilkat API has already been unlocked. // See Global Unlock Sample for example code. loImap = createobject("CkImap") // Connect to the IMAP server using SSL/TLS on the standard secure IMAP port. loImap.Ssl = .T. loImap.Port = 993 llSuccess = loImap.Connect("imap.example.com") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Authenticate with the IMAP server. llSuccess = loImap.Login("****","****") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Select the mailbox (folder) to access. llSuccess = loImap.SelectMailbox("Inbox") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Get the identifiers for all messages in the selected mailbox. // Setting fetchUids = cktrue causes IMAP UIDs to be returned. // If ckfalse, IMAP sequence numbers are returned instead. llFetchUids = .T. loMessageSet = createobject("CkMessageSet") llSuccess = loImap.QueryMbx("ALL",llFetchUids,loMessageSet) if (llSuccess = .F.) then ? loImap.LastErrorText release loImap release loMessageSet return endif // Download only the email headers for the messages in the set. // This is much faster than downloading full emails because the // message bodies and attachment contents are not retrieved. // // Even though the attachments themselves are not downloaded, // Chilkat can still provide information such as attachment // filenames, attachment sizes, and the total message size. loBundle = createobject("CkEmailBundle") llHeadersOnly = .T. llSuccess = loImap.FetchMsgSet(llHeadersOnly,loMessageSet,loBundle) if (llSuccess = .F.) then ? loImap.LastErrorText release loImap release loMessageSet release loBundle return endif // Iterate over each email in the bundle and display summary information. loEmail = createobject("CkEmail") i = 0 j = 0 do while i < loBundle.MessageCount loBundle.EmailAt(i,loEmail) // Display the sender and subject line. ? loEmail.From ? loEmail.Subject // Display all "To" recipients. j = 0 do while j < loEmail.NumTo ? "TO: " + loEmail.GetToName(j) + ", " + loEmail.GetToAddr(j) j = j + 1 enddo // Display all "CC" recipients. j = 0 do while j < loEmail.NumCC ? "CC: " + loEmail.GetCcName(j) + ", " + loEmail.GetCcAddr(j) j = j + 1 enddo // Display the total size of the email message, including // the body and all attachments, even though only headers // were downloaded. ? str(loEmail.Size) // When full emails are downloaded, attachment information // is accessed using the email.NumAttachments property and // the email.GetMailAttach* methods. // // However, because this example downloaded headers only, // attachment metadata must be obtained using the IMAP object. lnNumAttach = loImap.GetMailNumAttach(loEmail) j = 0 do while j < lnNumAttach // Display the attachment filename. ? loImap.GetMailAttachFilename(loEmail,j) // Display the attachment size in bytes. lnAttachSize = loImap.GetMailAttachSize(loEmail,j) ? " size = " + str(lnAttachSize) + " bytes" j = j + 1 enddo ? "--" i = i + 1 enddo // Disconnect from the IMAP server. llSuccess = loImap.Disconnect() release loImap release loMessageSet release loBundle release loEmail |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.