代码之家  ›  专栏  ›  技术社区  ›  RossFabricant

赎回的MAPI\ U E\ U FAILONEPROVIDER

  •  1
  • RossFabricant  · 技术社区  · 14 年前

    当我以自己的身份登录运行它时,此代码起作用:

    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
    

    2 回复  |  直到 10 年前
        1
  •  3
  •   Dmitry Streblechenko    14 年前

    经验法则是以可以访问相关邮箱的用户身份运行代码,请致电LogonExchangeMailbox以获取 现在的 用户,然后使用GetSharedMailbox打开其他用户的邮箱。

        2
  •  2
  •   RossFabricant    14 年前

    它还使用 Milan's blog .

            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;
            }