We currently use the following code to read an Inbox to find a specific email based on the messageid. Once found we extract information about the Outlook mail item like the subject, message text etc. Pretty stock standard stuff.
For iTemp = 1 To fol.Items.Count
If fol.Items(iTemp).EntryID = sMessageId Then
'Ok, we have our first match.
sMessageId = fol.Items(iTemp).EntryID
'Bring back all the variables
sTo = fol.Items(iTemp).To
sCC = fol.Items(iTemp).CC
sBCC = fol.Items(iTemp).BCC
sSubject = fol.Items(iTemp).subject
sText = fol.Items(iTemp).Body
sRecvDate = fol.Items(iTemp).ReceivedTime
sPriority = fol.Items(iTemp).Importance
sReadReceipt = IIf(fol.Items(iTemp).ReadReceiptRequested = False, 0, 1)
Set fol = Nothing
Set mainfolder = Nothing
ReadMessage = "SUCCESS"
As it is reading the properties of the email based on the number sequence it is found in the inbox - if a new email then arrives in the middle of this action - the wrong data then gets retrieved. e.g in the inbox I am reading email fol.Items(3).EntryID if another email then comes in, email 3 now becomes email 4 but the code is getting the properties of email 3 still which has just changed.
Is there a more robust way of doing this without the design flaw we have - seems a bit flaky if fol.items changes as emails come in ?
I recognise that changing the inbox view to sort ascending may resolve this but looking for a programmatical method because we cannot guarantee sort order.
Thanks in advance.