Reputation: 2984
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:
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)?
Upvotes: 1
Views: 256
Reputation: 2593
I'm going to preface this with the fact that this isn't an elegant solution, it should however work.
// check to see if outlook is running
System.Diagnostics.Process[] prcs = System.Diagnostics.Process.GetProcessesByName("outlook");
// if the found prcs length is 0, outlook isn't running
if(prcs.Length == 0)
{
// start outlook
System.Diagnostics.Process.Start("path to outlook");
// wait for outlook to load
// call your interop code
}
else
// outlook was found as an open process
// call your interop code
This works around your issue rather than resolving the underlying issue. Without an exception or anything else it's difficult to actually get to the bottom of.
Upvotes: 1