Jump to content
Sign in to follow this  

Outlook mail move breaks for loop

Recommended Posts

Hi guys,

I'm experiencing a weird thing here...

if i run this code:

$Outlook = ObjCreate('Outlook.Application')
    $namespace = $Outlook.GetNamespace("MAPI")
    $folder = $namespace.Folders("Foldername")
    $inbox = $folder.Folders("Inbox")
    $moveto = $inbox.Folders("Processed")
    ConsoleWrite("Mail Count: " & $inbox.Items.Count & @CRLF)
    For $item In $inbox.Items
        ConsoleWrite("-> " & $item.Subject & @CRLF)
        If Not @error Then
            ConsoleWrite("File Processed. " & @HOUR & ":" & @MIN & @CRLF)

The code seems to stop after 2 mails, even though there are more in there.

I have to keep recalling that function to do two mails at a time.

Now I've found one method to make it do all mails in just one time, but it means I have to comment the $item.Move($moveto) line.

Has anyone of you encountered this before and/or knows a fix?

Thanks in advance

Share this post

Link to post
Share on other sites

i wonder if the move is causing your handle to the item list index to get corrupted.

To test, you may wish to modify the function to be called from a loop, and get the collection / first message only per function call.

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...