Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

IMAP Download All Email One at a Time

Demonstrates how to download every email in an IMAP mailbox one at a time as a MIME string or as an email object. (The MIME contains the full contents of the email including all attachments.)

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oImap = ObjCreate("Chilkat.Imap")

;  This example requires the Chilkat API to have been previously unlocked.
;  See Global Unlock Sample for sample code.

;  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("myLogin","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

;  Once the mailbox is selected, the NumMessages property
;  will contain the number of messages in the mailbox.
;  You may loop from 1 to NumMessages to
;  fetch each message by sequence number.

Local $bUid = False
Local $sMimeStr
Local $i
Local $iN = $oImap.NumMessages
For $i = 1 To $iN

    ;  Download the email by sequence number.
    $sMimeStr = $oImap.FetchSingleAsMime($i,$bUid)

    ;  ... your application may process each MIME string...
Next

;  An alternative is to download each email in the form of an
;  email object, like this:
$oEmail = ObjCreate("Chilkat.Email")
For $i = 1 To $iN

    ;  Download the email by sequence number.
    $bSuccess = $oImap.FetchEmail(False,$i,$bUid,$oEmail)

    ;  ... your application may process the email object...

Next

;  Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()