Search code examples
c#outlookvstooutlook-addinfuzzing

How to trigger OnRead event for particular outlook VSTO addin?


I want to test(fuzz) outlook addin. The main idea is to develop addin(mail-generator) which will emulate\trigger mail opening for processing by my target addin. Is it possible emit OnRead event for target addin?

I thought my code must do the trick, but it won't:

string progId = "target_addin_progid";
var obj = (OUTLOOKADDINLib.ItemNotifications) Application.CreateObject(progId);
var msg = Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
msg.Body = "email body";
obj.ItemRead(msg);

I used debugger to ensure that above mentioned code don't reach to target addin processing logic. How to emulate mail reading using addin?


Solution

  • The Outlook object model doesn't provide any method or property for getting the events fired out of the box. You need to reproduce conditions under which the event is fired.

    You can simulare the Read event of the MailItem by saving it on the disk and changing the Selection from another item to the one you need to get the event fired, or just simply try to open it in the inspector window by calling the Display method of the MailItem class.