AutoIt
AutoIt
Fetch Single Email by UID or Sequence Number
Assuming the UID is known, download a single email by UID from an IMAP mail server.Chilkat AutoIt Downloads
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
$oEmail = ObjCreate("Chilkat.Email")
Local $iUid = 2014
Local $bIsUid = True
$bSuccess = $oImap.FetchEmail(False,$iUid,$bIsUid,$oEmail)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; 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)
; Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()