1
votes

I have Outlook VBA code that reads all incoming mails.
This code uses the MailItem to go through each mail looking at sender, to, subject and for attachments.
The heart of the code uses the urn:schemas feature that does a sql query on the inbox.
Thus if a new mail arrives the process that fires looks at the whole inbox every time and not just that mail. (The inbox is kept tidy and items are moved when processed.)

The heart of the query looks like this:

Dim Filter as String 
Filter = "urn:schemas:mailheader:subject  like  '%That report - %'"

Dim iMailMatch As Object
Set iMailMatch = Inbox.items.Find(Filter)

The problem is that (occasionally) when the machine is locked (not logged out), the macro will fire on a new mail event, but it won't find anything even though there are mails which match.
When I unlock the terminal and a new mail arrives - the process fires and it picks up/processes mails successfully that it previously didn't see.

The problem is only apparent when the terminal is locked. Thus I can only think that it has to do with kind of trust privileges.
There are times is does fire successfully when the terminal is locked, but it appears to be only when a mail arrives soon after the terminal is locked.

1
What events are you using NewMailEx or ItemsAdd event?0m3r

1 Answers

0
votes

Do not search. NewMailEx event passes the entry id of the new item to your event handler - open the item using Namespace.GetItemFromID, then read the MailItem.Subject property.