AutoIt
AutoIt
Copy an Email from One Mailbox to Another
Copies an email from one IMAP folder to another. After running this example, copies of the email will be present in both source and destination folders.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; This example copies an email from one mailbox to another.
$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("***","***")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Select an IMAP mailbox
$bSuccess = $oImap.SelectMailbox("Inbox.testing.a")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
Local $bFetchUids = True
; Get the message IDs for all emails having "Re:" in the subject.
$oMessageSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("SUBJECT Re:",$bFetchUids,$oMessageSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Copy the messages from "Inbox.testing.a" to "Inbox.testing.b" in one call to CopyMultiple:
$bSuccess = $oImap.CopyMultiple($oMessageSet,"Inbox.testing.b")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Alternatively, loop over each message in the set and
; copy each separately:
Local $i = 0
While $i < $oMessageSet.Count
Local $iMsgId = $oMessageSet.GetId($i)
Local $bIsUid = $oMessageSet.HasUids
$bSuccess = $oImap.Copy($iMsgId,$bIsUid,"Inbox.testing.c")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$i = $i + 1
Wend
; Display the session log.
ConsoleWrite($oImap.SessionLog & @CRLF)
; Disconnect from the IMAP server.
$bSuccess = $oImap.Disconnect()