2

我正在尝试使用用户兑换来更新用户的 Outlook 联系人。我正在影响的用户在 exchangeUser 中传递,称他为“目标用户”。当我以我自己的身份运行它时,此代码有效:

public OutlookFolders(string outlookRootFolder, string exchangeUser, string mailServer)
{
    var session = new RDOSessionClass();
    session.LogonExchangeMailbox(exchangeUser, mailServer);
    session.Stores.FindExchangePublicFoldersStore();
    var store = session.GetSharedMailbox(exchangeUser);
    //...
}

我试图以第三个用户“测试用户”的身份登录,他不是我,也不是“目标用户”。当我的程序到达 FindExchangePublicFoldersStore 时,我的程序会在运行时显示密码提示,如果我不填写我的凭据,它会失败并出现错误:

System.Runtime.InteropServices.COMException (0x8004011D): Error in 
    IMAPISession.OpenMsgStore(pbExchangeProviderPrimaryUserGuid):
    MAPI_E_FAILONEPROVIDER
ulVersion: 0
Error: Microsoft Exchange is not available.  Either there are network
    problems or the Exchange computer is down for maintenance.
Component: Microsoft Exchange Information Store
ulLowLevelError: 2147746069
ulContext: 1318

我尝试授予“目标用户”邮箱和联系人文件夹的“测试用户”所有者权限。似乎没有什么不同。需要设置哪些其他权限才能使其正常工作?

4

2 回答 2

3

经验法则是以可以访问相关邮箱的用户身份运行您的代码,为当前用户调用 LogonExchangeMailbox ,然后使用 GetSharedMailbox 打开其他用户的邮箱。

于 2010-07-01T16:26:22.653 回答
2

这是德米特里答案的代码。它还使用了Milan 博客中的一个功能。

        public OutlookFolders(string exchangeUser, string mailServer)
        {
            var session = new RDOSessionClass();
            var userFullName = GetFullName("DOMAIN-NT\\" + Environment.UserName);
            session.LogonExchangeMailbox(userFullName, mailServer);
            session.Stores.FindExchangePublicFoldersStore();
            var store = session.GetSharedMailbox(exchangeUser);
            rootFolder = store.GetDefaultFolder((rdoDefaultFolders)OlDefaultFolders.olFolderContacts);
        }

        public static string GetFullName(string strLogin)
        {
            string str = "";
            string strDomain;
            string strName;

            // Parse the string to check if domain name is present.
            int idx = strLogin.IndexOf('\\');
            if (idx == -1)
            {
                idx = strLogin.IndexOf('@');
            }

            if (idx != -1)
            {
                strDomain = strLogin.Substring(0, idx);
                strName = strLogin.Substring(idx + 1);
            }
            else
            {
                strDomain = Environment.MachineName;
                strName = strLogin;
            }

            DirectoryEntry obDirEntry = null;
            try
            {
                obDirEntry = new DirectoryEntry("WinNT://" + strDomain + "/" + strName);
                PropertyCollection coll = obDirEntry.Properties;
                object obVal = coll["FullName"].Value;
                str = obVal.ToString();
            }
            catch (System.Exception ex)
            {
                str = ex.Message;
            }
            return str;
        }
于 2010-07-02T14:01:06.320 回答