Pierre Savard

hi, I am using VSTO and I need to grab all incoming email to see if the subject have a certain TAG and if so I will do somthing.

I fist use the NewMailEx function, this is working well but I can't grab email received by a Send & Receive or when Outlook open in Cached mode. I read several post on the net exploring many solution but i can't found any conclusion of the best way to achieve that.

I read That I can use a timer to look a new email are in the inbox, but this solution is not verry reliable if my user read it before the timer event. Whats append if the user have several rules, I can't monitore all outlook folders! Someone have found a solution for this part

Thanks a lot.



Re: Visual Studio Tools for Office NewMailEx and cached mode

Helmut Obertanner

Hello Pierre,

you can try to Hook Up the Sync Objects within Outlook.

I have a sample here:

http://www.outlookcode.com/codedetail.aspx id=786

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office NewMailEx and cached mode

Pierre Savard

Thanks, I will try your code.

Can you tell me how to hook it in my plugin in the ThisAddins_Startup function

I try to convert your code in vb.net All woork good except this error telling me that I can't have two inherits. I think vb.net do not support this kind of inheritance. I remove the

Inherits Extensibility.IDTExtensibility2

it is okay

<GuidAttribute("9B73D13F-0476-4E16-86EF-A3A6B54EFFA8"), ProgId("XConnect.Connect")> Public Class AddIn

Inherits Object

Inherits Extensibility.IDTExtensibility2

Thanks





Re: Visual Studio Tools for Office NewMailEx and cached mode

Sue Mosher - Outlook MVP

NewMailEx should definitely be firing when new messages arrive in Cached Exchange mode, but tests suggest that you'll get only one ID per event in that scenario.



Re: Visual Studio Tools for Office NewMailEx and cached mode

Pierre Savard

Ok for the code provided by Helmut Obertanner I finaly found the solution and I can intercep send & Receive action. Thanks to you. Whats about intercepting the sent email, when sending a email the email are automatically sent, it is possible to intercept this email

Sue, I will make more test but actually in the NewMailEx function I only split the entryID string and put it in a public collection.

A timer in separate thread if fired every 30 sec to check if someting are in the collection. When Outlook are aleready open, the timer function foudn something in the public collection. but If I open Outlook and leave the initial synch occur (when outlook start in cahed mode and receive the firts batch of email from exchange server) the timer function never found items in the public collection.

I make another test: If I remove the cached mode and start outlook, the email receive on the initial synch do not fired the NewMailEX event. I think that the inital synch ethier in cached mode or not do not generate event... That confusing.





Re: Visual Studio Tools for Office NewMailEx and cached mode

Pierre Savard

Outlook programming is not simple!

To be able to use correctly the NewMailEX function I try to minimized the time to be sure I got all the call. To do so, I just add the entryID to a global collection and a timer do the "long" job of saving the email in a database. When someone make a outlook rule to move some email automatically, the entryID change when the rule move the email to another folders! When my timed function is called the email does not exist anymore with the old EventID! Someone have some suggestion for that

Thanks again





Re: Visual Studio Tools for Office NewMailEx and cached mode

Helmut Obertanner

Hello Pierre,

there are several methods how to sync Outlook items with a database.

One is:

Create a Guid and save it in a field with your Item e.g. Mileage.

Others use the ConversationTopic

Or you could use a combination of time received, subject & sender to identify a unique email

Or - Create a TicketNumber and insert it into the Subject

However, the EntryID sometimes changing, e.g. also if you have replication between multiple servers (as I know)

There are also some old (raising dust, cough, cough) - samples out there that checks for new emails like:

this:

http://www.outlookcode.com/codedetail.aspx id=795

or This:

http://www.outlookcode.com/codedetail.aspx id=793

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office NewMailEx and cached mode

Pierre Savard

Thanks I will try that!

By the way How Can I limit to email only excluding the Read Receipt email message with this line:

And of I leave MessageClass = IMP.Post, unreadInboxItems always empty! The folder used are the Inbox

unreadInboxItems = inboxFolder.Items.Restrict("[MessageClass] = 'IPM.Post' AND [unread] = true")

Any Suggesiont





Re: Visual Studio Tools for Office NewMailEx and cached mode

Helmut Obertanner

Hello Pierre,

the MessageClass for a MailItem is IPM.Note as I now.

IPM.Post is a PostItem.

A ReadReceipt will have a Messageclass beginning with "REPORT.IPM.Note.DR" -> DeliveryReport or

"REPORT.IPM.Note.IPNDR" ReadReport.

Note that there could be more different types of Items in the Inbox like

Appointment .Accept, Decline, Tentative, etc.

So ("[MessageClass] = 'IPM.Note' AND [unread] = true") is a good option to start.

Hope this helps,

greets, Helmut