I'm using interop to get me a list of all local outlook contacts (code below). It all works fine except for one case: When I don't have outlook open during the time Iam using that code I get a messagebox which disappears after about 2 seconds again. The messagebox asks me (translated thus the english version is probably slightly different): "Configuring mailboxxyz-accept Server configuration for this website?"
After looking at the message and looking how the local things are configured I saw that my company is using a certificate in outlook and as it is looking it is so that:
- If outlook is running then my interop functions are using the certificate and thus the messagebox does not pop up
- If outlook is not running then my interop functions are not automatically using the certificate and thus the popup comes and asks if I want to accept it.
What adds a layer of strangeness there is that the usage of the functions succeeds and the messagebox pops up a few seconds AFTER the functions have finished and then disappears after 2 seconds.
Microsoft.Office.Interop.Outlook.Application outlookHandler = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.Items outlookItemsCollection;
MAPIFolder folderContacts = (MAPIFolder)outlookHandler.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
outlookItemsCollection = folderContacts.Items;
foreach (var outlookItem in outlookItemsCollection)
{
.....
}
Also another way to get this phenomenon: When outlook is not running I can try to start it:
Microsoft.Office.Interop.Outlook.Application outlookHandler = new Microsoft.Office.Interop.Outlook.Application();
var mm = outlookHandler.GetNamespace("MAPI");
mm.Logon(Type.Missing, Type.Missing, true, true);
// Same for the second true being false instead.
When I do this outlook asks for the certificate after asking for the default profile.
My question here is now: Is there any way to prevent this popup from happening (or to tell the interop methods to use the certificate without asking)?