![]() |
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) Read IMAP Email HeadersCall FetchHeaders to download only the email headers. Note: This example requires Chilkat v11.0.0 or greater.
Local $bSuccess = False ; This example requires 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("****","****") 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 ; Get the message IDs of all the emails in the mailbox ; We can choose to fetch UIDs or sequence numbers. Local $bFetchUids = True $oMessageSet = ObjCreate("Chilkat.MessageSet") $bSuccess = $oImap.QueryMbx("ALL",$bFetchUids,$oMessageSet) If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit 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. $oBundle = ObjCreate("Chilkat.EmailBundle") Local $bHeadersOnly = True $bSuccess = $oImap.FetchMsgSet($bHeadersOnly,$oMessageSet,$oBundle) If ($bSuccess = False) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Loop over the email objects and display information ; about each: $oEmail = ObjCreate("Chilkat.Email") Local $sName Local $sAddr Local $i = 0 Local $iJ = 0 While $i < $oBundle.MessageCount $oBundle.EmailAt($i,$oEmail) ; Display the From and Subject ConsoleWrite($oEmail.From & @CRLF) ConsoleWrite($oEmail.Subject & @CRLF) ; Display the recipients: $iJ = 0 While $iJ < $oEmail.NumTo ConsoleWrite("TO: " & $oEmail.GetToName($iJ) & ", " & $oEmail.GetToAddr($iJ) & @CRLF) $iJ = $iJ + 1 Wend $iJ = 0 While $iJ < $oEmail.NumCC ConsoleWrite("CC: " & $oEmail.GetCcName($iJ) & ", " & $oEmail.GetCcAddr($iJ) & @CRLF) $iJ = $iJ + 1 Wend ; Show the total size of the email, including body and attachments: ConsoleWrite($oEmail.Size & @CRLF) ; 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: Local $iNumAttach = $oImap.GetMailNumAttach($oEmail) $iJ = 0 While $iJ < $iNumAttach ConsoleWrite($oImap.GetMailAttachFilename($oEmail,$iJ) & @CRLF) Local $iAttachSize = $oImap.GetMailAttachSize($oEmail,$iJ) ConsoleWrite(" size = " & $iAttachSize & " bytes" & @CRLF) $iJ = $iJ + 1 Wend ConsoleWrite("--" & @CRLF) Wend ; Disconnect from the IMAP server. $bSuccess = $oImap.Disconnect() |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.