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) Fetch Single Email by UID or Sequence NumberAssuming the UID is known, download a single email by UID from an IMAP mail server.
; 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 $oEmail Local $iUid = 2014 Local $bIsUid = True $oEmail = $oImap.FetchSingle($iUid,$bIsUid) If ($oImap.LastMethodSuccess = True) Then ; Display the From and Subject ConsoleWrite($oEmail.FromAddress & @CRLF) ConsoleWrite($oEmail.Subject & @CRLF) ; Display the Body property, which is the default body. ; If an email has an HTML body, the Body property contains ; the HTML source. Otherwise it contains the plain-text ; body. ConsoleWrite("---- EMAIL BODY ----" & @CRLF) ConsoleWrite($oEmail.Body & @CRLF) ConsoleWrite("--------------------" & @CRLF) ; Display the recipients: Local $iJ For $iJ = 0 To $oEmail.NumTo - 1 ConsoleWrite($oEmail.GetToName($iJ) & ", " & $oEmail.GetToAddr($iJ) & @CRLF) Next For $iJ = 0 To $oEmail.NumCC - 1 ConsoleWrite($oEmail.GetCcName($iJ) & ", " & $oEmail.GetCcAddr($iJ) & @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) ConsoleWrite($iNumAttach & @CRLF) 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) EndIf ; Disconnect from the IMAP server. $bSuccess = $oImap.Disconnect() |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.