Auto Discover Exchange Server settings using Aspose.Email for Java 18.5

aspose-email-for-javaAspose.Email for Java 18.5 has been released. This month’s release includes new feature of Auto Discovery of Exchange Server settings using the API’s EWS client. It also enhances the PST to Exchange server import operation. For a detailed note on what is new and fixed, please visit the release notes section of the API documentation.

Support for Auto Discovery Feature using Aspose.Email for Java 18.5

This release introduces a new feature of auto-discovery of Exchange server settings using account’s user name and password. The AutoDiscoverService introduced by the API gets this information from the exchange server using the username and password specified by application user. In addition to other settings returned by the API, you can get the server’s EWS Url as well using this feature.

String email = "...";
String password = "...";
AutodiscoverService svc = new AutodiscoverService();
svc.setCredentials(new NetworkCredential("username@domain.com", "password"));

IGenericDictionary<Integer,Object> userSettings = svc.getUserSettings(email, UserSettingName.ExternalEwsUrl).getSettings();
String ewsUrl = (String)userSettings.get_Item(UserSettingName.ExternalEwsUrl);
System.out.println("Exchange Server Url: " + ewsUrl);

Abort PST to Exchange Server Operation

Import of large size PSTs to Exchange server can result in operation timeout which can lead to unexpected results. This month’s release provides the capability to defined timeout for the operation so that it can stop upon meeting the desired criterion. This allows users to abort the PST restore operation in case it is taking too long to complete the operation.

PersonalStorage pst = PersonalStorage.fromFile("");
		
IEWSClient client = EWSClient.getEWSClient("https://exchange.domain.com", "username", "password");
		
final AtomicInteger numberOfProcessedItems = new AtomicInteger(0);

RestoreSettings rs  = new RestoreSettings();
		
rs.setBeforeItemCallback(new BeforeItemCallback() {
    public void invoke(ItemCallbackArgs item) {
        if (numberOfProcessedItems.get() >= 1)
        {
            throw new AbortRestoreException();
        }

        numberOfProcessedItems.incrementAndGet();
    }
});

try {
    client.restore(pst, rs);
} catch (AbortRestoreException e) {
    System.out.println("1 resored");
}

API Resources

We have detailed information available online for getting started with the Aspose.Email for Java API. These are: