![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java 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 HeadersCall FetchHeaders to download only the email headers. Note: This example requires Chilkat v11.0.0 or greater.
llSuccess = .F. // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loImap = createobject("CkImap") // Connect to an IMAP server. // Use TLS loImap.Ssl = .T. loImap.Port = 993 llSuccess = loImap.Connect("imap.example.com") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Login llSuccess = loImap.Login("****","****") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Select an IMAP mailbox llSuccess = loImap.SelectMailbox("Inbox") if (llSuccess = .F.) then ? loImap.LastErrorText release loImap return endif // Get the message IDs of all the emails in the mailbox // We can choose to fetch UIDs or sequence numbers. llFetchUids = .T. loMessageSet = createobject("CkMessageSet") llSuccess = loImap.QueryMbx("ALL",llFetchUids,loMessageSet) if (llSuccess = .F.) then ? loImap.LastErrorText release loImap release loMessageSet return endif // When downloading headers, each email object contains // (obviously) the headers, but the body will be missing. // Also, attachments will not be included. However, it is // possible to get information about the attachments // as well as the complete size of the email. 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 // Loop over the email objects and display information // about each: loEmail = createobject("CkEmail") i = 0 j = 0 do while i < loBundle.MessageCount loBundle.EmailAt(i,loEmail) // Display the From and Subject ? loEmail.From ? loEmail.Subject // Display the recipients: j = 0 do while j < loEmail.NumTo ? "TO: " + loEmail.GetToName(j) + ", " + loEmail.GetToAddr(j) j = j + 1 enddo j = 0 do while j < loEmail.NumCC ? "CC: " + loEmail.GetCcName(j) + ", " + loEmail.GetCcAddr(j) j = j + 1 enddo // Show the total size of the email, including body and attachments: ? str(loEmail.Size) // When a full email is downloaded, we would use the // email.NumAttachments property in conjunction with the // email.GetMailAttach* methods. // However, when an email object contains only the header, // we need to access the attachment info differently: lnNumAttach = loImap.GetMailNumAttach(loEmail) j = 0 do while j < lnNumAttach ? loImap.GetMailAttachFilename(loEmail,j) lnAttachSize = loImap.GetMailAttachSize(loEmail,j) ? " size = " + str(lnAttachSize) + " bytes" j = j + 1 enddo ? "--" enddo // Disconnect from the IMAP server. llSuccess = loImap.Disconnect() release loImap release loMessageSet release loBundle release loEmail |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.