Tony Gravagno
Guest
|
I'm using the ADXMAPIStoreAccessor (.NET4/Outlook 2010) to intercept new inbound e-mail. The intent is to sort the mail items into different folders based on criteria like From Name or Address, To, CC, Subject, and various headers. I already have this functionality in VBA with Redemption and want to migrate it into an AddIn.
When the OnNewMail event is fired, I may want to move it to another folder.
Is the mail item already in the Inbox when this event is executed?
I'm guessing ADXMAPINewMailNotificationEventArgs.StoreId should be Inbox.
Is Outlook._MailItem.Move() valid within this handler?
I'm not sure if ADXMAPIStoreAccessor requires that an operation like this be performed in some special way in order to ensure the object is modified - and I don't want to move the object out from under some other handler.
Should I wait for some other event to query and move a folder item?
Since we're here, I've been through the blogs discussing the NewMail, NewMailEx, and logging inbound mail to make sure it's not missed by some process. Does ADXMAPIStoreAccessor_OnNewMail eliminate the need for other methods to capture new mail? The information available isn't clear on this. Just how effective is OnNewMail and when should we attempt to overcome its inadequacies?
Thanks! |
|
Eugene Astafiev
Guest
|
|
Tony Gravagno
Guest
|
Eugene, I just finished testing with this code. Of course you are 100% correct. :) After running this through debug it occurs to me that it doesn't matter if new e-mail has been stored in the Inbox yet. Moving the mail item is done with item.Move(toFolderObj). It's irrelevant where the object is because we're not moving it from anywhere. We're just operating on the object and telling it where it will be.
I have read your "Handling NewMail.." article several times (and pretty much every other blog available on this site). I guess material like that becomes more clear after we write code to implement what we've learned. This is what I understand from that article:
Use the StoreAccessor to process new items, and feel confident that with a local PST file it "should" get everything. However, for Exchange, some backup code is required which may find unprocessed emails in the Inbox and process them. Those unprocessed items are the effect of the sync issue mentioned in the article.
The following article documents a process which I believe would serve as a good backup as indicated above:
http://www.add-in-express.com/creating-addins-blog/2011/11/10/outlook-newmail-custom-solution/
Rather than using a timer and a local datastore to automatically detect unprocessed items in the Inbox, I'm going to provide a button which allows the user to manually process whatever items they select in any file.
In summary, the StoreAccessor has been a great help. So far it has allowed me to replace VBA code which used CDO and Redemption. Thanks! |
|
Eugene Astafiev
Guest
|
You are always welcome, Tony! :-) |
|