Use Microsoft.Office.Interop.Outlook from c# to access non-default profiles

136 Views Asked by At

I'm trying to pull Outlook store information from the non-default profile. The solution here does essentially what I want, except it only pulls from the default profile. According to MS documentation, I should be able to specify the profile with the NameSpace.Logon method. But no matter what I specify with NameSpace.Logon, I only get stores from the default profile.

For example, this code just outputs the default profile ("Outlook"), not the "archive" profile:

using Microsoft.Office.Interop.Outlook;
...
Application objApp = null;
NameSpace ns = null;
objApp = new Application();
ns = objApp.GetNamespace("MAPI");
ns.Logon("archive");
Console.WriteLine(ns.Session.CurrentProfileName);

I've also tried using the Logon method with the Application.Session object, rather than the Application.Namespace object, but I get the same result.

2

There are 2 best solutions below

9
Eugene Astafiev On

Make sure that no outlook.exe processes exist in the list of running processes. Outlook is a singleton, if any instance has not been closed and still running on the system, you will not be able to logon to another profile and continue dealing with the current session/profile.

0
Adam J. Kessel On

I wasn't able to figure out why this wasn't working with c# code, but I did find the command-line tool MrMAPI, which can get me most of the way there. mrmapi -profile lists the profiles available, and then mrmapi -profile (profile_name) -store (store_name) dumps metadata associated with each of the stores for the specified profile. From there I can extract the other information I need. I would like to figure out why the Interop code shown above never worked but this is a reasonable workaround.

Incidentally, mrmapi is able to retrieve info about other profiles even when Outlook is running with the default profile. I don't know if this contradicts the singleton observation above or if mrmapi is accessing the profiles some other way.