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
(AutoIt) Read IMAP Email HeadersCall FetchHeaders to download only the email headers.
; 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 Local $bSuccess = $oImap.Connect("imap.someMailServer.com") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Login $bSuccess = $oImap.Login("****","****") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Select an IMAP mailbox $bSuccess = $oImap.SelectMailbox("Inbox") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf Local $oMessageSet ; We can choose to fetch UIDs or sequence numbers. Local $bFetchUids = True ; Get the message IDs of all the emails in the mailbox $oMessageSet = $oImap.Search("ALL",$bFetchUids) If ($oImap.LastMethodSuccess <> True) 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. Local $oBundle $oBundle = $oImap.FetchHeaders($oMessageSet) If ($oImap.LastMethodSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Loop over the email objects and display information ; about each: Local $i For $i = 0 To $oBundle.MessageCount - 1 Local $oEmail $oEmail = $oBundle.GetEmail($i) ; Display the From and Subject ConsoleWrite($oEmail.From & @CRLF) ConsoleWrite($oEmail.Subject & @CRLF) ; Display the recipients: Local $iJ Local $sName Local $sAddr For $iJ = 0 To $oEmail.NumTo - 1 $sName = $oEmail.GetToName($iJ) $sAddr = $oEmail.GetToAddr($iJ) ConsoleWrite($sName & ", " & $sAddr & @CRLF) Next For $iJ = 0 To $oEmail.NumCC - 1 $sName = $oEmail.GetCcName($iJ) $sAddr = $oEmail.GetCcAddr($iJ) ConsoleWrite($sName & ", " & $sAddr & @CRLF) Next ; 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) For $iJ = 0 To $iNumAttach - 1 ConsoleWrite($oImap.GetMailAttachFilename($oEmail,$iJ) & @CRLF) Local $iAttachSize = $oImap.GetMailAttachSize($oEmail,$iJ) ConsoleWrite(" size = " & $iAttachSize & " bytes" & @CRLF) Next ConsoleWrite("--" & @CRLF) Next ; Disconnect from the IMAP server. $bSuccess = $oImap.Disconnect() |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.