简体   繁体   中英

Microsoft.Exchange.WebServices.Data.ServiceResponseException: Unable to access an account or mailbox thrown for user having fullright access

I have two users a@company.com and b@company.com . I am trying to access b's mailbox from user a using EWS Managed API . User a has fullright permissions on b's mailbox. I can even open b's mailbox from a's account from Outlook Web Access.

But when trying to access b's mailbox I am getting this exception.

Microsoft.Exchange.WebServices.Data.ServiceResponseException: Unable to access an account or mailbox.

Here is the relevant code

            var mailbox = new Mailbox("b@company.com");
            var folderId = new FolderId(WellKnownFolderName.Inbox, mailbox);
            Folder lyncFolder;
            try
            {
                // Getting  ServiceResponseException : Unable to access an account or mailbox                              
                lyncFolder = Folder.Bind(_exchangeService, folderId);
            }
            catch (ServiceResponseException ex)
            {
                _logger.Error(ex);

                    throw;

            }

Here is the request trace

<Trace Tag=\"EwsRequest\" Tid=\"7\" Time=\"2015-10-07 11:04:47Z\" Version=\"15.00.0847.030\">
  <?xml version=\"1.0\" encoding=\"utf-8\"?>
  <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
    <soap:Header>
      <t:RequestServerVersion Version=\"Exchange2013_SP1\" />
    </soap:Header>
    <soap:Body>
      <m:GetFolder>
        <m:FolderShape>
          <t:BaseShape>AllProperties</t:BaseShape>
        </m:FolderShape>
        <m:FolderIds>
          <t:DistinguishedFolderId Id=\"inbox\">
            <t:Mailbox>
              <t:EmailAddress>b@company.com</t:EmailAddress>
            </t:Mailbox>
          </t:DistinguishedFolderId>
        </m:FolderIds>
      </m:GetFolder>
    </soap:Body>
  </soap:Envelope>
</Trace>

Here is the response trace

<Trace Tag="EwsResponse" Tid="7" Time="2015-10-07 04:19:05Z" Version="15.00.0847.030">
  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
      <s:Fault>
      <faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorMailboxConfiguration</faultcode>
      <faultstring xml:lang="en-US">Unable to access an account or mailbox.</faultstring>
      <detail>
        <e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorMailboxConfiguration</e:ResponseCode>
        <e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">Unable to access an account or mailbox.</e:Message>
      </detail>
      </s:Fault>
    </s:Body>
  </s:Envelope>
</Trace>

here goes response headers

Transfer-Encoding : chunked
request-id : 26ee43ea-6444-4f6c-abb0-f041fdb6dde6
X-CalculatedBETarget : BLUPR01MB116.prod.exchangelabs.com
X-BackEndHttpStatus : 500
x-EwsHandler : GetFolder
X-DiagInfo : BLUPR01MB116
X-BEServer : BLUPR01MB116
X-FEServer : SIXPR04CA0091
Cache-Control : private
Content-Type : text/xml; charset=utf-8
Date : Wed, 07 Oct 2015 10:54:15 GMT
Set-Cookie : exchangecookie=e6f7d9dad36b40ad918050eefbd3d25c; path=/
Server : Microsoft-IIS/8.0
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET

The behavior I have observed is when I open b's mailbox from a's account from OWA manually, the exception goes away and I can access b's mailbox from the code. And again later, the same exception again resurfaces randomly when I have to again open b's mailbox from a's account from OWA manually and the cycle continues. Any Idea?

Ok. It looks like that error can crop up if you have a configuration issue, likely more than one user with the same SMTP address. So for example, if you have more than one use with b@company.com listed as an SMTP address, you might see this error.

This might be related with Impersonation , try put this line in your code:

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, b@company.com);

There's 3 ways to enable users to access other users' mailboxes:

  1. By adding delegates and specifying permissions for each delegate.
  2. By modifying folder permissions directly.
  3. By using impersonation.

Each way has its limitations, you can find the details from that link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM