Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Fetch Inbox Email HeadersDownloads the headers of all emails in the Inbox and shows some information about each, such as From, Subject, and whether the email has been seen (already read) or not.
Use ChilkatAx-win32.pkg Procedure Test Handle hoImap Boolean iSuccess Variant vBundle Handle hoBundle Integer i Variant vEmailHeader Handle hoEmailHeader Integer iSeenFlag String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatImap)) To hoImap If (Not(IsComObjectCreated(hoImap))) Begin Send CreateComObject of hoImap End // Connect to an IMAP server. // Use TLS Set ComSsl Of hoImap To True Set ComPort Of hoImap To 993 Get ComConnect Of hoImap "imap.someMailServer.com" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Login Get ComLogin Of hoImap "myLogin" "myPassword" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Select an IMAP mailbox Get ComSelectMailbox Of hoImap "Inbox" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Normally, when an email is downloaded, its "Seen" flag is automatically set. // We don't want our program to be interfering with the "Seen" flags. // To do this, set the PeekMode to True. Set ComPeekMode Of hoImap To True // After selecting the mailbox, the NumMessages property // will contain the number of emails in the mailbox. // When sequence numbers (not UIDs) are used to reference emails, // they range from 1 to N, where N is the number of messages in the mailbox. // This example will download the headers by sequence numbers. Get ComNumMessages Of hoImap To iTemp1 Get ComFetchSequenceHeaders Of hoImap 1 iTemp1 To vBundle If (IsComObject(vBundle)) Begin Get Create (RefClass(cComChilkatEmailBundle)) To hoBundle Set pvComObject Of hoBundle To vBundle End Get ComLastMethodSuccess Of hoImap To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End Get ComMessageCount Of hoBundle To iTemp1 If (iTemp1 = 0) Begin Showln "No messages in Inbox." Send Destroy of hoBundle Procedure_Return End // Loop over the email headers. Get ComMessageCount Of hoBundle To iTemp1 For i From 0 To (iTemp1 - 1) Get ComGetEmail Of hoBundle i To vEmailHeader If (IsComObject(vEmailHeader)) Begin Get Create (RefClass(cComChilkatEmail)) To hoEmailHeader Set pvComObject Of hoEmailHeader To vEmailHeader End Get ComFrom Of hoEmailHeader To sTemp1 Showln sTemp1 Get ComSubject Of hoEmailHeader To sTemp1 Showln sTemp1 // Get the "Seen" flag. // When an email is fetched from the IMAP server, the email flags are stored // within the email in the "ckx-imap-flags" header. // The call to GetMailFlag is simply getting the information from the email header. // (it is not communicating with the IMAP server to get this information, because // the information was obtained when downloading the headers) Get ComGetMailFlag Of hoImap vEmailHeader "Seen" To iSeenFlag If (iSeenFlag = 1) Begin Showln "This email has been read (already seen)" End Else Begin Showln "This email has not yet been read (it is not yet seen)" End // We can also look directly at the "ckx-imap-flags" header: Get ComGetHeaderField Of hoEmailHeader "ckx-imap-flags" To sTemp1 Showln "ckx-imap-flags: " sTemp1 Showln "--" Send Destroy of hoEmailHeader Loop Send Destroy of hoBundle // Disconnect from the IMAP server. Get ComDisconnect Of hoImap To iSuccess End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.