Sample code for 30+ languages & platforms
AutoIt

Delete IMAP Email

To delete an email, the "Deleted" flag must be set to 1 for each message to be deleted. You must also call Expunge or ExpungeAndClose to remove the emails marked as deleted.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

; This example deletes email matching a criteria from Inbox.
$oImap = ObjCreate("Chilkat.Imap")

; Turn on session logging:
$oImap.KeepSessionLog = True

; 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

Local $bFetchUids = True
; Get the message IDs for all emails having "FTP2" in the subject.
$oMessageSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("SUBJECT FTP2",$bFetchUids,$oMessageSet)
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

; Set the Deleted flag for each message:
$bSuccess = $oImap.SetFlags($oMessageSet,"Deleted",1)
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

; Expunge and close the mailbox.
$bSuccess = $oImap.ExpungeAndClose()
If ($bSuccess = False) Then
    ConsoleWrite($oImap.LastErrorText & @CRLF)
    Exit
EndIf

; Display the session log.
ConsoleWrite($oImap.SessionLog & @CRLF)

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