AutoIt
AutoIt
Delete Individual Emails from POP3 Mailbox
Demonstrates how to delete individual emails from a POP3 mailbox.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; The mailman object is used for receiving (POP3)
; and sending (SMTP) email.
$oMailman = ObjCreate("Chilkat.MailMan")
; Set the POP3 server's hostname
$oMailman.MailHost = "pop.example.com"
; Set the POP3 login/password.
$oMailman.PopUsername = "myLogin"
$oMailman.PopPassword = "myPassword"
; Set the ImmediateDelete property = False
; When the DeleteEmail method is called, the POP3 session
; will remain open and the emails will be deleted all at once
; when the session closes.
$oMailman.ImmediateDelete = False
; Download email headers.
$oBundle = ObjCreate("Chilkat.EmailBundle")
Local $bKeepOnServer = True
Local $bHeadersOnly = True
Local $iNumBodyLines = 1
$bSuccess = $oMailman.FetchAll($bKeepOnServer,$bHeadersOnly,$iNumBodyLines,$oBundle)
If ($bSuccess = False) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
$oEmail = ObjCreate("Chilkat.Email")
Local $i = 0
While $i < $oBundle.MessageCount
$oBundle.EmailAt($i,$oEmail)
ConsoleWrite("From: " & $oEmail.From & @CRLF)
ConsoleWrite("Subject: " & $oEmail.Subject & @CRLF)
; If you decide the email is to be deleted, call DeleteEmail.
; This marks the email for deletion on the POP3 server.
$bSuccess = $oMailman.DeleteEmail($oEmail)
If ($bSuccess = False) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
$i = $i + 1
Wend
; Make sure the POP3 session is ended to finalize the deletes.
$bSuccess = $oMailman.Pop3EndSession()
If ($bSuccess = False) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Success!" & @CRLF)