Ticket #3043: Outlook_test.au3

File Outlook_test.au3, 1.3 KB (added by apoliemans, 5 years ago)

testcase FOR..IN..NEXT loop deleting Outlook mailitems

Line 
1#include <Debug.au3>
2
3_DebugSetup("Debug Out", False, 1)
4_DebugOut("Debug start")
5
6;-----------------------------------------------------------------------
7; Setup Outlook environment
8;-----------------------------------------------------------------------
9$olApp       = ObjCreate("Outlook.Application")
10$olNameSpace = $olApp.GetNameSpace("MAPI")
11Dim $archive = $olNameSpace.PickFolder
12
13;-----------------------------------------------------------------------
14; Save number of mails to Drafts folder
15;-----------------------------------------------------------------------
16$timestamp = @HOUR & ":" & @MIN & ":" & @SEC
17Dim $Mail
18for $i = 1 to 10
19   _DebugOut("Adding mail #" & $i)
20   $Mail = $olApp.CreateItem(0)
21   $Mail.Subject = "Test mail (" & $timestamp & ") [" & $i & "]"
22   $Mail.HTMLBody = "<HTML><p>test</p></HTML>"
23   $Mail.save()
24   Sleep(1000)
25Next
26
27;-----------------------------------------------------------------------
28; Delete all items using a FOR..IN..NEXT loop
29;-----------------------------------------------------------------------
30$oParentFld = $Mail.Parent
31$iteration = 0
32For $j in $oParentFld.Items
33   $iteration += 1
34   _DebugOut("Deleting mail, loop " & $iteration)
35   $j.Delete
36   Sleep(1000)
37Next
38
39_DebugOut("Loop has finished, " & $oParentFld.Items.Count & " items remaining in folder.")