Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Problem retrieving (email) items in Inbox folder using getfirst - getnext loop

$
0
0

Hi,

i am trying in a VBScript to display all items in the inbox, using the getfirst - getnext methode in a do while loop. The ultimate goal is to move certain items to another folder, so a for each loop can't be used.

I retrieve the first item by the getfirst mehode, and then start the do loop, display some information of the first item, and then retrieve the next item (within the loop). The second item is then also displayed, but then this second item keeps displaying and the loop never ends.

Set objApplication = CreateObject("Outlook.Application")
objApplication.GetNamespace("MAPI").Logon , , , False
Set objMyNameSpace = objApplication.GetNameSpace("MAPI")
Set objInboxFolder = objMyNameSpace.GetDefaultFolder(6)
intMessageCount = objInboxFolder.Items.Count
MsgBox("Number of items in Inbox: " & CStr(intMessageCount))
Set objMessage = objInboxFolder.Items.GetFirst ' Get the first message
' Loop through the collection
Do While Not objMessage Is Nothing    MsgBox ("Sender = " & objMessage.SenderName & vbCRLF & "ReceivedTime = " & CStr(objMessage.ReceivedTime) & vbCRLF & _               "Unread = " & Cstr(objMessage.Unread) & vbCRLF & "address name = " & objMessage.SenderName & vbCRLF & _               "address address = " & objMessage.SenderEmailAddress & vbCRLF & "Subject = " & objMessage.Subject & vbCRLF & _               "EntryId = " & objMessage.EntryID)  Set objMessage = objInboxFolder.Items.GetNext ' Get next message
Loop

I am using Office (Outlook) 2010. Can sombody tell me why i only get the first two items to display.







Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>