How to access the archive folder when user's mailbox is on-premise and the archive mailbox is in the cloud.

If you have found that accessing a cloud archive folder is not working using the EWS Managed API when the user's mailbox is on-premise then you may need to add some code to your application.  To get it to work you will either need to know the password for the archive mailbox or much better is to have password replication setup so that the same password can be used for both the user's mailbox and for their archive.  To get to the archive your EWS code will need to first get its SMTP address by calling AutoDiscover for the user in order to get it. Then using that SMTP address your code would call autodiscover again to get the end-point EWS URL of the archive mailbox. After all that your code should be able to use the EWS URL for the archive mailbox, its SMTP address and password to access the  mailbox.

You will need two service objects in order to get to the archive mailbox.  The first one is to get to the AutoDiscover settings which provide the SMTP address of the archive mailbox.  The second service object uses the archive mailbox SMPT address in an AutoDiscover  call in order to get the URL for the archive mailbox. 

In order for your EWS code to access both the on premise mailbox and the archive mailbox with the same credentials, both need to be set to use the same credentials.  This can be done manually or with password replication.  If password replication is not setup for your cloud archive then an Exchange Online case should be opened.

Use the EWS Managed API to:

Your going to need to write a little more code to get to the archive folder when the mailbox is on-premise and the archive is in the cloud. 

  • Create a service object and do AutoDiscover on the user mailbox.  

  • Use the service object to do a "GetUserSettings" in order to get back a "GetUserSettingsResponse" object.  GetUserSettingsResponse performs a call to the Exchange AutoDiscover service in order to gather user configuration settings. 

    Below is what the returned XML may look like when the archive mailbox is in the cloud.  Note the Type node is set to "Archive" and that there is an SMTPAddress set.:

      <UserSetting i:type="AlternateMailboxCollectionSetting">
          <Name>AlternateMailboxes</Name>
        <AlternativeMailbox>
          <Type>Archive</Type>
          <DisplayName>In-Place Archive – Bob Smith</DisplayName>
          <SmtpAddress>da25f3ab-2939-4f46-8dbd-175c2421c137@mycompany.mail.onmicrosoft.com</SmtpAddress>
          <OwnerSmtpAddress> bobsmith@mycompany.com</OwnerSmtpAddress>
        </AlternativeMailbox>
</AlternateMailboxes>
      </UserSetting>

In comparison, this is what the same setting may look like for an on-premise archive:

         <UserSetting i:type="AlternateMailboxCollectionSetting">
             <Name>AlternateMailboxes</Name>
          <AlternateMailboxes>
        <AlternateMailbox>
            <Type>Archive</Type>
            <DisplayName>Personal Archive - Bob Smith</DisplayName>
            <LegacyDN i:nil="true" />
            <Server i:nil="true" />
            <OwnerSmtpAddress>bobsmith@mycompany.com</OwnerSmtpAddress>
                             </AlternateMailbox>
       </AlternateMailboxes>
        </UserSetting>

  • The "GetUserSettingsResponse" object will contain a lot of properties including "Microsoft.Exchange.WebServices.Autodiscover.AlternateMailboxCollection".  This collection will contain an entry for the archive mailbox – look for the entry with the type "Archive" and get the SmtpAddress from it.

// The sample below is from "AutodiscoverViewer.cs" in EWSEditor.

case ("Microsoft.Exchange.WebServices.Autodiscover.AlternateMailboxCollection"):

Microsoft.Exchange.WebServices.Autodiscover.AlternateMailboxCollection oCollection3;
oCollection3 = (Microsoft.Exchange.WebServices.Autodiscover.AlternateMailboxCollection)usersetting.Value;

    foreach (AlternateMailbox oAlternativeMailbox in oCollection3.Entries)

{

            sValue += string.Format(
                            "Type: {0} \r\n" +
                            "DisplayName: {1} \r\n" +  
                            "LegacyDN: {2} \r\n" +     
                            "Server: {3} \r\n" +
                            "SmtpAddress: {4} \r\n" +
                            "OwnerSmtpAddress: {5} \r\n" +
                            "\r\n",

                oAlternativeMailbox.Type,
                oAlternativeMailbox.DisplayName,
                oAlternativeMailbox.LegacyDN,
                oAlternativeMailbox.Server,
                oAlternativeMailbox.SmtpAddress,
                oAlternativeMailbox.OwnerSmtpAddress

        ValueCount++;
                   }

  • Create a NEW service object and do AutoDiscover for the SMTP address returned by GetUserSettingsResponse.   This will initialize this new service object for access to the archive mailbox. 
  • Be sure to use the credentials of the mailbox.  If the credentials do not work then credentials replication may not be setup.
  • Note that since the archive mailbox is in the cloud that EnableScpLookup should be set to false on the service object prior to calling AutoDiscover in order to skip SCP AutoDiscover processing since SCP AutoDiscover is ONLY to be used when a mailbox is in the same domain as the client.
  • Use the new service object to work against the archive mailbox.

To do the same in EWSEditor:

Part 1 - Get the archive mailbox SMTP address.

  • Do Autodiscover against the Mailbox to get the alternative mailbox address for the archive mailbox.  Note that the latest build of EwsEditor can do this via the AutodiscoverViewer window.
  • Use EWSEditors AutodiscoverViewer window to get the user settings then find the Alternative Mailboxes line and double-click on the line - a window showing various values will be displayed.
  • From there find the section which has the Type "Archive" and note the SMTP address associated with it - is the SMTP address of the archive mailbox. It may be best to copy the address into notepad because it is likely going to be very long.  Note that there may other alternate mailboxes listed. 
  • At this point you have the SMTP address of the archive mailbox - now, you need to use it to get to the contents of the archive folder.

Part 1 - Get the archive mailbox SMTP address.

  • Next, do Autodiscover using the mailbox credentials and the archive folder SMTP address.  This can be done using File/New Exchange Service then right clicking on the first node in the file hierarchy tree open the archive mailbox root folder (just ignore error window, which is a test that’s done against mailboxes to verify EWS works – it’s not a valid test in this case).
  • If the credentials do not work then password replication may not have been setup for the archive mailbox. 
  • If password replication is not setup then you can use the replication mailboxes credentials if you know them. 
  • If you need help with setting up password replication then consider opening an Exchange Online support case.