![]() |
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
(AutoIt) Download Unread Email from IMAP MailboxDownload unread email messages from an IMAP mailbox. Note: This example requires Chilkat v11.0.0 or greater.
Local $bSuccess = False ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oImap = ObjCreate("Chilkat.Imap") ; Connect to an IMAP server. ; Use TLS $oImap.Ssl = True $oImap.Port = 993 $bSuccess = $oImap.Connect("imap.example.com") If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Login $bSuccess = $oImap.Login("admin@chilkatsoft.com","myPassword") If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Select an IMAP mailbox $bSuccess = $oImap.SelectMailbox("Inbox") If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Find emails marked as seen or not already seen: Local $seenSearch = "SEEN" Local $sNotSeenSearch = "NOT SEEN" ; Get the set of unseen message UIDs Local $bFetchUids = True $oMessageSet = ObjCreate("Chilkat.MessageSet") $bSuccess = $oImap.QueryMbx($sNotSeenSearch,$bFetchUids,$oMessageSet) If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Fetch the unseen emails into a bundle object: $oBundle = ObjCreate("Chilkat.EmailBundle") Local $bHeadersOnly = False $bSuccess = $oImap.FetchMsgSet($bHeadersOnly,$oMessageSet,$oBundle) If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Display the Subject and From of each email. $oEmail = ObjCreate("Chilkat.Email") Local $i = 0 Local $iNumEmails = $oBundle.MessageCount While $i < $iNumEmails $oBundle.EmailAt($i,$oEmail) ConsoleWrite($oEmail.GetHeaderField("Date") & @CRLF) ConsoleWrite($oEmail.Subject & @CRLF) ConsoleWrite($oEmail.From & @CRLF) ConsoleWrite("--" & @CRLF) $i = $i + 1 Wend ; Disconnect from the IMAP server. $bSuccess = $oImap.Disconnect() |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.